How to achieve physics entity with trigger and on ground?

Basically I want physics entity that initially will spawn at mid air and then pull down by physics gravity then stay on top of ground with physics. Then physics entity will able to pick up by player by using trigger event. How can I achieve that? Currently it seems like when u setup physics entity to become dynamic to have physics collision then u no longer able to set trigger event for player to pick up without collision that will get weird push physics collision when player trying to pick it and also can't use ITriggerEventsJob anymore to detect trigger event. If can't setup like that, what's the correct setup to achieve the goal?

@daniel-holz I would like to know is there any solution to solve this or currently It's limitation of ecs physics?

Hi,

It is possible to change a collider's filter and collision response at runtime, kinda like this:

var collider = state.EntityManager.GetComponentData<PhysicsCollider>(myPhysicsEntity);
collider.Value.Value.SetCollisionFilter(new CollisionFilter { BelongsTo = 0, CollidesWith = 0 });
collider.Value.Value.SetCollisionResponse(CollisionResponsePolicy.RaiseTriggerEvents);
state.EntityManager.SetComponentData(myPhysicsEntity, collider);

Bear in mind if you're using this same collider for other objects, those will also be changed, unless you create a separate Clone() of the collider first..

1 Like


I no need to change physics collider behavior at runtime. Basically what actually want is just spawn some kind of pickup entity at mid air and then pull down by physics gravity then stay on top of ground with physics that I believe should have both physics body and physics shape. And then when player touches pickup entity, it should able to destroy it immediately which I believe requires RaiseTriggerEvents but I think physics entity can't support both RaiseTriggerEvents and RaiseCollisonEvent. So I needs to have Collide collision response only to ground meanwhile RaiseTriggerEvents only to player. This two needs to happens at the same time for the entire pickup entity lifetime that can't switch to one another. How can I achieve this? @daniel-holz Let me know if u have any good solution to solve this problem.

I might be saying stupid, i have not tried it myself yet, but you can in theory add two collider to your object, one will have the raise trigger event and appropriate belongsTo and collidesWith filter in order to only trigger with the player collider, and one will have classic collider that does not collide with player collider, but does collide with the floor. Put the same shape on the two. As the material filter is per collider and not per rigidbody, i do not see (at least yet) where it could go wrong.

1 Like

@optimise : I have trouble understanding a part in your use case description.

Do you want to switch between a dynamic and a static rigid body at any point here?
Also, am I understanding correctly that you want to have a dynamic rigid body with a collider that only raises trigger events but doesn't cause dynamics contacts leading to contact forces to be generated?

If you want to be alerted about a collision between some dynamic rigid body (the one you describe falls down against gravity and lands on the ground where it stays at rest) and another player entity, you can add an additional collider on your player entity that only raises trigger events.

1 Like


I guess pickup entity needs to dynamic rigid body so it will stay on top of group pull by physics gravity instead of drop into ground? Basically I want to achieve the goal by using only one single collider that avoid pickup entity drops into and able pickup by player and destroy pickup entity itself nicely but currently if I remember correctly, set to Collider and RaiseCollisonEvent will just push pickup entity because of physics when player trying to pick the pickup entity. How to solve this issue without creating yet another new collider at the same pickup entity?

Do it the way daniel-holz suggested, adding the trigger to the player.


For performance reason I can't really add an additional collider to do it since it's dots netcode game at mobile platform that currently it's extremely taxing and also I looks like hack fix solution. I would like official addresses this issue and come out with better solution.

One extra collider shouldn't make a significant impact on performance.
Would it be many you have to add?

If you try it and do some profiling, it would help understand if this is indeed feasible.

Other than that you could also use the "collide and raise trigger" option for the hand collider but from what I understand you don't want collisions to be created since the hand would push the object you want to grab away.

1 Like