Kinematic to Dynamic wierd behaviour

Hi

I am using this code to make my kinematic colliders dynamic when the arrows hit:

                        commandBuffer.SetComponent(entityInQueryIndex, entity,
                            PhysicsMass.CreateDynamic(MassProperties.UnitSphere, 20));
                        commandBuffer.AddComponent(entityInQueryIndex, entity, new PhysicsDamping
                        {
                            Linear = 0.01f,
                            Angular = 0.05f
                        });
                        commandBuffer.RemoveComponent<PhysicsGravityFactor>(entityInQueryIndex, entity);

But the colliders behave very wierd when they switch to dynamic:

6331434--702639--wierdcol.gif

Any ideas how I can fix this?

The only thing I see so far is that you should probably do something like this for the mass:

var colliderComponent = EntityManager.GetComponentData(entity);
commandBuffer.SetComponent(entityInQueryIndex, entity, PhysicsMass.CreateDynamic(colliderComponent.MassProperties, 20.0f));

This will keep the mass properties of the capsule instead of using the one for the sphere. Let me know if that changes anything.

Thanks, this helped a little. But the capsules are still bouncing around on the floor without anything impacting them.

Heres the Colliders settings:

Can I see the new behavior after the mass fix? It might help me figure out what’s happening… Also, is there anything else you do to these entities when they are hit by arrows other than the code you shared above?

So even just normal capsules nothing else, they keep bouncing around:

6338286--703956--ezgif.com-optimize.gif
When I keep it running after a while it looks like this still bouncing:

I am using the latest 0.5.0-preview.1 physics package.

The capsules seem setup fine, I’ve just tried with the exact same values and everything looks fine on my end. What about the ground below them? Can you show me the setup for it? Also, is there any custom code handling collision events and similar?

Can you also try adding a Physics Debug Display component to a general scene node that is being converted to an Entity (e.g. the node you might have a Physics Step component on)? Then turn on the display for Mass Properties and Collider Edges.
Also, what is the Restitution of the floor? The Restitution combine option is set to Maximum so if the floor has a higher value it won’t matter if the Capsule is set to 0.

1 Like

EDIT: Just solved the problem by lowering the scale on the floor.

This is the floor:

6339900--704268--upload_2020-9-23_11-37-23.png

I have some ICollisionEventsJob’s defined, but nothing that should impact the capsules or the floor.

I have now also tried with different settings on the capsules (extrapolation, intrapolation, no scale) but getting similar results:
6339900--704274--upload_2020-9-23_11-42-57.png

Draw Mass Properties is not really working for me it flickers on the smaller capsules and when I pause it disappears:

6339900--704277--upload_2020-9-23_11-44-23.png

I’ve also added Physics Step and tried to set “Enable Contact Solver Stability” but this also had no effect on the bouncing:
6339900--704280--upload_2020-9-23_11-45-35.png

So with a floor scale of 1000,1,1000 it works well. Then as I increase the scale the capsules start bouncing. At 10000,1,10000 the capsules bounce all over the place. So the way to go is just to use multiple smaller floor colliders?

EDIT: Looks like I don’t even need a floor bigger than 1000x1000 so my problem is solved.

3 Likes

Interesting find! Sounds like you were hitting floating point precision problems with that scale then. Similar behavior happens if you were simulating your capsules out beyond 5km from the origin as well.

2 Likes