Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | GreasyMcBeef |
I have a KinematicBody2D player object and some StaticBody2D platform objects. If the player collides with an object with a normal within an angular range that I’ve designated as the floor, I want the player to adjust its rotation to match the angle of the floor and snap down (i.e. rotate about the corner that contacts the surface). This is fine until we encounter a situation in which the player contacts the sloped floor at a position where the floor intersects another platform that’s at a different angle, since rotating and snapping down would cause us to intersect and jitter between the two floors.
My proposed solution was to rotate and snap, and then check if we’re intersecting any platforms. If we aren’t intersecting, we’re fine and can move on, but if we are intersecting, then undo the rotation and snap, and try again with a smaller angle a few times to find a close approximation to the angle that rests the KinematicBody2D’s CollisionShape2D on top of both platforms, at the angle of the line between the collision points (see image below).
My problem lies in the ability to check if our rotation would cause an overlap. If using test_move
with a rel_vec
argument of Vector2(0,0), we still detect a collision even when just sitting on a single floor, I guess since the objects are touching (I measured to ensure my math was correct, and the player rests perfectly on the floor).
My next thought was to try attaching an Area2D to the kinematic body with the same CollisionShape2D as the one I attached to the kinematic body, and then call get_overlapping_bodies
on it, but if I’m interpreting the results correctly, it doesn’t count the new overlapping platforms until the next physics process. I also can’t just use an Area2D’s overlapping signals, since I need to be able to reverse the rotate and snap mid-process to try a different one.
Does anyone have advice on how to best proceed? Thanks!