SOLVED! Link to solution
Godot Version
v4.4.stable.steam [4c311cbee]
Question
I’m having trouble with ShapeCast2Ds not detecting RigidBody2Ds with CollisonPolygon2Ds.
Sometimes, the collision is detected; other times, it isn’t. Here are some instances where a collision is not detected (look to the left of the image):
(One thing I’ve noticed is that in all of these instances, the top-half of the shapecast is colliding with nothing and the bottom-half is colliding with part of a piece. Maybe that has something to do with the problem, but I’m not entirely sure.)
I’ve double checked both the ShapeCast2D and the RigidBody2D. The ShapeCast2D has masks 1 and 3; the RigidBody2D has layers 1 and 3 to match.
The intended result is that once the ShapeCast2D detects the piece, the piece is destroyed. That doesn’t happen in the image examples above; the enemy simply gets stuck.
Here’s are some video examples of a collision failing to be detected before being successfully detected by the addition of another RigidBody:
And here’s how I code the checks for RigidBody2Ds:
func _physics_process(delta: float) -> void:
if front_shapecast.is_colliding():
var collider = front_shapecast.get_collider(0)
print(collider)
#print(collider.get_class())
if collider is Guy:
collider.hurt(damage)
death()
elif collider is PieceBody: # <- This is what the ShapeCast2D should be colliding with
collider.hp -= damage
death()
Note that the ShapeCast2D is colliding with PieceBodys (the Tetris-looking RigidBody2Ds)



