Return MoveAndSlideHitReponse enum from on_hit callback#933
Conversation
| planes.push(Dir::new_unchecked(sweep_hit.normal1.f32())); | ||
| } else if hit_response == MoveAndSlideHitResponse::Abort { | ||
| break; | ||
| } |
There was a problem hiding this comment.
how come an ignore doesn't continue here?
There was a problem hiding this comment.
Ignore skips this specific surface (i.e. doesn't push the plane like Accept does) but continues processing other hits. The rest of the hits here are processed below in intersections.
The semantics here are a bit confusing since Ignore doesn't ignore the actual shape cast hit. The shape is still moved up to the surface, but the return value of the callback just determines what to do with each plane found at that point, which affects the velocity projection. Having it ignore the shape cast hit would require a filter on the shape cast itself (tbf we should have this too), not on the collection of collision planes.
Tangentially related: I wonder if using Abort on the first hit is actually equivalent to move_and_collide in Godot, or slide: false in Rapier 🤔 I think it should be; it stops at the first hit and then aborts move-and-slide without any sliding
Objective
The callbacks for
move_and_slideandintersectionsdon't currently work like their docs describe. The former should abort when the callback returns false (currently it just ignores a single hit), and the latter doesn't actually do anything with the returned boolean.For
move_and_slide, the callback should ideally return an enum with three variants: accept the hit, ignore the hit but continue, and ignore the hit and abort. Forintersections, the callback should still return a boolean, but it should actually abort whenfalseis returned.Solution
Add a
MoveAndSlideHitResponseenum:This is handled as the docs describe.
Also make
intersectionsabort further hit processing when the callback returnsfalse.