Why is ShapeCast2D colliding, but can also move its full length without collision?

Godot Version

Windows 11, Godot 4.2.1

Question

A RigidBody2D rests on top of a StaticBody2D. A ShapeCast2D is pointed down from the RigidBody. Calling is_colliding() on the ShapeCast2D returns true. Why does get_closest_collision_safe_fraction() return a value of 1?

Here’s the docs entry on get_closest_collision_safe_fraction():

The fraction from the ShapeCast2D 's origin to its target_position (between 0 and 1) of how far the shape can move without triggering a collision.

My understanding of this is that a 1 means that moving the full length of the ShapeCast would trigger no collisions and a 0 means the shape can not move at all without triggering collisions. So if is_colliding() is true, how can get_closest_collision_safe_fraction() be any value above 0? Does get_closest_collision_safe_fraction() ignore any object that the shape is already colliding with at its origin?

Details on the two Bodies:

RigidBody2D is size 128x128 square
StaticBody2D is size 128x128 square
ShapeCast2D is child of the RigidBody2D, centered on it, and size 128x128. Target position is default value (0, 50).

Does get_closest_collision_safe_fraction() ignore any object that the shape is already colliding with at its origin?

In case anyone comes across this question in the future:

I did one more test and may have answered this question with a Yes for myself.

I moved the position of the Shapecast to 1 pixel above the edge of the RigidBody instead of being aligned exactly with it, and the results were immediately as I expected.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.