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.42k stars 414 forks source link

[Feature Request] CharacterVirtual needs support for enhanced internal edge removal #1085

Closed SheridanR closed 4 months ago

SheridanR commented 4 months ago

Hi,

Based on my experiments, while regular rigid bodies support the new internal edge removing collector, none of that is implemented for the CharacterVirtual controller, so it doesn't work on that feature at all.

My request is simple, that the CharacterVirtual implementation be extended to support this feature as well as rigid bodies do. I've made some attempts at this myself already, but haven't had any luck - I'm probably missing something, but simply dropping it in wherever CollisionDispatch is needed has not done the trick, so I'm at a bit of a loss about what to do next.

Very hopeful something can be done about this, as my simulation involves a lot of "tiled" shapes with overlapping edges (unfortunately), and while rigid bodies now glide smoothly over them now thanks to this new feature, my character controller sure doesn't...

Thanks in advance for any help or advice!

jrouwe commented 4 months ago

Hello,

In my experience, CharacterVirtual deals very well with internal edges. The character has some padding around it (CharacterVirtualSettings::mCharacterPadding) that prevents it from directly hitting the edge and this smooths the normals to such an extent that it barely responds to them. Perhaps your padding is very small in comparison to your character size?

SheridanR commented 4 months ago

Hi there,

I started with all default settings on a capsule with 1m radius, but even at speeds of a few m/s (realistic jogging speed) my character is liable to penetrate walls and catch internal edges, which causes big problems as this can cause the character to rebound in very unexpected directions when there is low "friction" (eg if the character is jumping through the air).

Experiments with setting these variables to all kinds of values has not produced satisfactory results - the character still catches internal edges continually.

I've made sure to generate the static geometry as a compound body, and I've witnessed internal edge removal working fine for dynamic bodies - I'm just disappointed it doesn't appear to work for CharacterVirtual, as well. 🤔

jrouwe commented 4 months ago

I've added a new flag CharacterVirtualSettings::mEnhancedInternalEdgeRemoval that allows you to enable the internal edge removal algorithm.

SheridanR commented 4 months ago

Thank you very much!