Add kinematic collide-and-slide helper. - #6546
Conversation
|
I believe this test failure is unrelated to my changes. |
|
|
||
| private static bool CanKinematicMoveCastShape(IPhysShape shape) | ||
| { | ||
| return shape switch | ||
| { | ||
| PhysShapeCircle => true, | ||
| PolygonShape => true, | ||
| Polygon => true, | ||
| SlimPolygon => true, | ||
| _ => false, | ||
| }; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Won't this box them as some shapes have been ported to structs.
| private bool TryCastShapeClosest( | ||
| MapId mapId, | ||
| IPhysShape shape, | ||
| Transform origin, | ||
| Vector2 translation, | ||
| QueryFilter filter, | ||
| out KinematicMoveHit hit) | ||
| { |
There was a problem hiding this comment.
Generics better as below r.e. boxing.
| if (!fixture.Hard || | ||
| fixture.CollisionLayer == 0x0 || | ||
| fixture.CollisionMask == 0x0 || | ||
| !CanKinematicMoveCastShape(fixture.Shape)) |
There was a problem hiding this comment.
This looks like a box2d port because box2d uses AND for layer / mask collisions but we still use godot's OR so are you really sure it should filter out if layer or mask is 0 atm?
| { | ||
| private const int DefaultKinematicMoveIterations = 4; | ||
| private const float DefaultKinematicMoveSkin = 0f; | ||
| private const float KinematicMoveEpsilon = float.Epsilon; |
There was a problem hiding this comment.
These really should not be constants as they look like they were built for single-purpose and should be CVars. All the other physics constants have purpose for being constants but even the solver iterations are configurable.
They also need documenting.
|
Rest looks good fwiw. |
|
Box2D includes these now so I would prefer to port those to use ideally. |
Adds a small
CollideAndSlidehelper onRayCastSystemfor swept kinematic movement.This builds on the existing shape cast path and clips the remaining translation along hit planes without changing physics solver behavior. It intentionally does not depenetrate initial overlaps, matching existing shape cast behavior.