AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [tf2] hook when physics objects collide? (https://forums.alliedmods.net/showthread.php?t=319184)

foon 10-18-2019 12:31

[tf2] hook when physics objects collide?
 
Im wondering if there is a way to test when a physics object (pipebomb, stickybomb, milk, jarate, etc [it does work with all flairs, but not gaspasser]) hits another?

I am spawning in a model and setting the solidtype to vphysics, It triggers with rockets fine, but no physics objects. I have tried all collision groups, but none work. Any ideas?

Code:

}
int entity = CreateEntityByName("prop_physics_override");
        if (IsValidEntity(entity))
        {
                SetEntityModel(entity, model);
                DispatchKeyValue(entity, "StartDisabled", "false");
                DispatchSpawn(entity);
               
                TeleportEntity(entity, origin, NULL_VECTOR, NULL_VECTOR);
               
                SetEntProp(entity, Prop_Send, "m_usSolidFlags", 12); // FSOLID_NOT_SOLID|FSOLID_TRIGGER
                SetEntProp(entity, Prop_Data, "m_nSolidType", 6); // SOLID_VPHYSICS
                SetEntProp(entity, Prop_Send, "m_CollisionGroup", 2); // COLLISION_GROUP_DEBRIS
                AcceptEntityInput(entity, "Enable");
               
                SDKHook(entity, SDKHook_StartTouch, Hook_OnTouch);
        }
}

public Action Hook_OnTouch(int call, int client)
{
        PrintToServer("touched");
}


Dragokas 10-18-2019 14:38

Re: [tf2] hook when physics objects collide?
 
Did you try SDKHook_ShouldCollide ?

Also, may be helpful for you:
https://forums.alliedmods.net/showthread.php?t=197815

foon 10-18-2019 15:09

Re: [tf2] hook when physics objects collide?
 
SDKHook_ShouldCollide seems to use the boundingbox instead of VPhysics, so if the model is concave or rotated, it wont work (unless I am doing something wrong here). I just tested CollisionHook after I made my first post, but it seems its not updated anymore and doesn't work.

Dragokas 10-19-2019 07:21

Re: [tf2] hook when physics objects collide?
 
And what about SDKHook_Touch instead StartTouch?

What "model" variable = ? Is it a model supporting physics at all?
Try prop_physics instead.

foon 10-19-2019 10:16

Re: [tf2] hook when physics objects collide?
 
I have tried SDKHook_Touch, yes. I got CollisionHook working, but it is exactly the same as using SDKHook in this case. The model is custom and it does support physics. I have also tried prop_physics (and override) but its the same.

If you want to check out the model, here it is: https://files.catbox.moe/rx61p6.zip

Here are some pics too.
https://i.imgur.com/BTzp6HW.png
https://i.imgur.com/jGTFIJt.png

And here is an example, if I shoot through the corners, it still registers as getting hit. Its like its using the bbox instead of vphysics.
https://i.imgur.com/9ZwbOIx.png

BHaType 10-20-2019 00:34

Re: [tf2] hook when physics objects collide?
 
You can try to use this

https://developer.valvesoftware.com/...lisionProperty
CCollisionProperty::SetSurroundingBoundsType( SurroundingBoundsType_t, Vector const*, Vector const*)

or this

https://developer.valvesoftware.com/wiki/Bounding_box
UTIL_SetSize() or CBaseEntity::SetSize()

foon 10-20-2019 10:53

Re: [tf2] hook when physics objects collide?
 
I have gone through all the settings for m_nSurroundType, but its still exactly the same. It either triggers with the bbox/rbox/absbox, or it doesn't trigger at all. Is there maybe a way where I can parent a rocket to the sticky/pipe and still keep the physics of the sticky/pipe?

nosoop 10-21-2019 10:03

Re: [tf2] hook when physics objects collide?
 
For collisions between physics objects (including world), you may want to hook CBaseEntity::VPhysicsCollision(int index, gamevcollisionevent_t* event) with DHooks.

The first argument determines which array index represents its own values in the collision event argument (0 or 1).

Here's some information about the offsets within the gamevcollisionevent_t struct for TF2, should you need it:

Code:

// vphysics_interface.h
abstract_class IPhysicsCollisionData {
public:
        virtual void GetSurfaceNormal( Vector &out ) = 0;
        virtual void GetContactPoint( Vector &out ) = 0;
        virtual void GetContactSpeed( Vector &out ) = 0;
}

// public/vphysics_interfaceV30.h
struct vcollisionevent_t {
        IPhysicsObject*                        pObjects[2]; // 0x00, 0x04
        int                                                surfaceProps[2]; // 0x08, 0x0C
        bool                                        isCollision; // 0x10
        bool                                        isShadowCollision; // 0x11 ??
        float                                        deltaCollisionTime; 0x14
       
        float                                        collisionSpeed; // 0x18
        IPhysicsCollisionData*        pInternalData; // 0x1C
}

// game/server/physics.h
struct gamevcollisionevent_t : vcollisionevent_t {
        Vector                                        preVelocity[2]; // 0x20, 0x2C
        Vector                                        postVelocity[2]; // 0x38, 0x44
        AngularImpulse                        preAngularVelocity[2]; // 0x50, 0x5C
        CBaseEntity*                        pEntities[2]; // 0x68, 0x6C
}



All times are GMT -4. The time now is 00:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.