RayCast2D Odd Behaviour

Godot Version

4.2.2

Question

I’m having trouble understanding why having a RayCast2D Node as a child of my CharacterBody2D behaves differently/oddly when it is a child of another node under CharacterBody2D.

Screenshot 2024-05-29 at 9.41.42 PM

This works as expected. When my player jumps, the raycast is_colliding() is false in the air and true on the ground. If I move the raycasts as a child of NodeFlip2D (just a base Node2D used for scaling the animated_sprite_2d), it keeps detecting is_colliding() as true even when I am in the air.


I was wondering what was going on and I turned on visible collision shapes under debug and sure enough, they are detecing collision when in the air.

I am trying to learn about RayCasts, I made a question earlier today you may have seen it, so, just to be clear, what are you using the FlipNode 2D for?

And why are you scaling it?

I’m using the FlipNode2D to flip the character sprite instead of just using AnimatedSprite2D.flip_h so I can have a RayCast2D flip with the sprite for wall detection.

Can we see the full Transform info from the Inspector for FlipNode2D?

Without see how is the raycast position and the character body is a bit hard to tell, but i’ll guess the problem is because when you reparent the raycast, the exclude_parent property will exclude the NodeFlip2D from the detection, but will detect your character body so will mark as collision, you can do a test and make sure your character will be always undetectable from your raycast using YourRayCast.add_exception(YourCharacter) (if the code is called from the character you can use YourRayCast.add_exception(self))

I figured out I needed to change the collision mask, but still wonder why it’s not needed when the RayCast2D is a direct child of the parent.
Screenshot 2024-05-30 at 6.37.35 PM


Screenshot 2024-05-30 at 6.38.42 PM