Check intersect_ray normal is not a zero vector, to ensure the ray is colliding with and not just enclosed in the shape. #41277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While investigating #41167, I noticed that
RectangleShape2D
returns theObject
when callingget_collider()
for aRayCast2D
that is completely enclosed by the shape. However,CapsuleShape2D
,CircleShape2D
andConvexPolygonShape2D
all return null. The other shapes don't create enclosures.In 3D Bullet physics, all of the Shapes (
BoxShape3D
,CapsuleShape3D
,CylinderShape3D
,SphereShape3D
andConvexPolygonShape3D
) return null when callingget_collider()
if theRayShape3D
is completely enclosed. However, in Godot 3D physics,BoxShape3D
andCapsuleShape3D
also return theObject
when callingget_collider()
and a zero length normalVector3
when callingget_collision_normal()
. TheSphereShape3D
and theConvexPolygonShape3D
don't. Godot 3D physics doesn't support theCylinderShape3D
.This patch makesRect2D::intersects_segment()
andAABB::intersects_segment()
returnfalse
when the segment doesn't intersect an edge or a face respectively, and hence doesn't set the normal to a zero length vector either.This patch checks that
intersects_segment()
sets thenormal
to a normal vector, to ensure the ray is colliding with and not just enclosed in the shape, before deciding there is a collision.This makes all shapes consistently return
null
when callingget_collider()
if theRaycast
is completely enclosed in the shape.