jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6.72k stars 447 forks source link

The VirtualCharacter doesn't find the ground contacts when mMaxSlopeAngle is above 60 degrees #892

Closed AndreaCatania closed 9 months ago

AndreaCatania commented 9 months ago

Hello, I'm debugging an issue on the virtual character which is failing to gather the contact with this moving platform, so it's not able to stay on it.

https://github.com/jrouwe/JoltPhysics/assets/8342599/605e38c9-ba27-4a50-b1bc-a730ba1cb0f8

I've noticed that this bug goes away by reducing the mMaxSlopeAngle to anything below 55 degrees.

https://github.com/jrouwe/JoltPhysics/assets/8342599/bae0560d-5ea6-466f-9ac4-8b82759cefec

Anything above 55 degrees (in radians 0.959931) cause this issue. Maybe there is something which is clamped to 1? This bug is quite noticeable with 60 / 70 degrees.

AndreaCatania commented 9 months ago

Just after posting this I've discovered that reducing mMaxSlopeAngle is not fixing it. This bug happens randomly and I've the impression there is some undefined behavior somewhere, I'm double checking all my code once again and update this issue once I've better results.

jrouwe commented 9 months ago

This is one of the test cases in the CharacterVirtualTest:

https://github.com/jrouwe/JoltPhysics/assets/1621693/c6c37733-7425-4b21-a2e2-74b8cf293310

so I would expect this to work.

Is the platform maybe moved by updating its position (BodyInterface::SetPosition) instead of moving it kinematically (BodyInterface::MoveKinematic)? This would cause the CharacterVirtual to be unable to follow the platform since the velocity is not set. I can also imagine this being client/server specific where the server moves a platform kinematically and the client just follows it by setting the position.

Perhaps you can try to alter CharacterVirtualTest with the parameters of your in game platform to see if you can repro it?

AndreaCatania commented 9 months ago

Is the platform maybe moved by updating its position

Nope, it's moved by changing its LinearVelocity.

I can also imagine this being client/server specific where the server ...

This can't be the case as the platform is simulated on both the client and the server.

Perhaps you can try to alter CharacterVirtualTest with the parameters of your in game platform to see if you can repro it?

I'll try reproducing it there; something to note is that the platform is using a convex shape not a primitive box, maybe that's the problem? This is just a guess though.

AndreaCatania commented 9 months ago

Apparently re-implementing the platform movement using MoveKinematic fixes the problem (at least for now). The MoveKinematic function is not doing much other than setting the linear velocity as I was doing, not sure why directly set the linear velocity was causing that issue. I'm closing this issue for now, and open it again if this issue appears again (which is totally possible).

Thanks for the help!!