Facepunch / garrysmod-requests

Feature requests for Garry's Mod
84 stars 24 forks source link

Allow SENTs to change return value of CBaseEntity::PhysicsSolidMaskForEntity() #208

Open Jcw87 opened 10 years ago

Jcw87 commented 10 years ago

It would be very useful if scripted entities could define their own CONTENTS masks. For example, I want to have an entity block players and physics objects, but not bullets. This can only be achieved by changing the return value of CBaseEntity::PhysicsSolidMaskForEntity().

There used to be a function to do this, but it was removed in some update, and I can't remember what it was called before.

UnderscoreKilburn commented 10 years ago

I gave it a try and it doesn't allow you to set the contents of the entity. It seems to be used to define what the entity can collide with, but not the other way around. I tried to find another way but it seems to be deep inside the engine trace code and I haven't found anything of interest yet, so tell me if you have any lead.

Jcw87 commented 10 years ago

I've done some more investigation into how traces are filtered. It seems that custom filtering is handled in CEngineTrace::TraceRay with a callback in ITraceFilter (which is used for things like preventing the player entity that fired a bullet from being hit by it), while normal filtering happens in CEngineTrace::ClipRayToCollideable. If the collision model is a studiomodel, it will first check that model for a CONTENTS mask and test the trace mask against it. This can be illustrated by spawning in a 'models/props_c17/fence01a.mdl', and shooting through it. Things seem to get a lot more complicated when custom collision meshes are involved (my entity uses Entity:PhysicsInitConvex). Even if I set my entity model to the fence model before using Entity:PhysicsInitConvex, bullets won't pass through, despite my tests with a server plugin that show that the engine still thinks it has the fence collision model and CONTENTS mask.

Whatever funky stuff Garry did to make custom collision meshes work, it doesn't play nice with the existing trace filter mechanisms.

h3xcat commented 6 years ago

Bump, this request is 3 years old. And I would really appreciate if this feature is added in next updates.

h3xcat commented 6 years ago

https://github.com/Facepunch/garrysmod-requests/issues/1055 This in a way allows you to "set" content flags.

robotboy655 commented 6 years ago

no, only retrieve them

h3xcat commented 6 years ago

Doesn't returning nothing makes the rays to go pass through the entity?

local sent_contents = CONTENTS_PLAYERCLIP + CONTENTS_MONSTERCLIP

function ENT:TestCollision( startpos, delta, isbox, extents, mask )
    if bit.band( mask, sent_contents ) ~= 0 then
        return {}
    end
    return nil
end
h3xcat commented 6 years ago

Yeah, my alternative solution didn't work after the update. I really hoped it did. You need to return new hit pos which is bit hard to calculate.

h3xcat commented 6 years ago

I believe this got implemented in next update?

Can anyone confirm this also work with Entity:PhysicsInitConvex?

Zet0rz commented 5 years ago

I believe this got implemented in next update?

Setting the physics object to for example CONTENTS_EMPTY will make props pass through properly, but traces still hit, meaning players, nextbots, bullets, and lua traces will still collide with the entity regardless of what the physics object's Contents is. util.PointContents will also still return the default value, CONTENTS_SOLID for the entity/model I tested with.

Can anyone confirm this also work with Entity:PhysicsInitConvex?

Appears to have no effect on that either, beyond props being able to pass through.

Exposing this function would be very useful for creating things like props that only block players or NPCs using the various clip enums.

robotboy655 commented 4 years ago

Yeah this hook unfortunately doesn't do much, the coolest thing it can is making entities collide with NPCCLIP brushes.

Kefta commented 4 years ago

I thought the whole point of this hook was for changing interactions with brushes/player movement. https://github.com/Facepunch/garrysmod-requests/issues/1074 and https://github.com/Facepunch/garrysmod-requests/issues/1085 would be more useful though.