S

raycast only works in upper 90 degrees

Sketch Armstrong(Sketch Armstrong)

This is a link to my project as of writing

I'm attempting to create a shield mob that only attacks the robot if it is not behind a wall, and it does work, but only for and it doesn't rotate, either. If the robot leaves this region of the shield's Area2Ds, then it stops chasing it. Sorry, I'm sort of at a loss on where to go from here. Because looking at the script it looks like it should work normally, to me.


  • S
    Sketch Armstrong(Sketch Armstrong) replied

    I figured it out. I just had to turn off "Collide With: Areas"


  • S
    Sketch Armstrong(Sketch Armstrong) replied

    Though I would appreciate it if someone explained what exactly was going on, regardless, so I know what to look out for in the future. Thank you

  • Nathan Lovato replied

    The reason is that with areas turned on, your raycast would often detect the SpellHolder of the Robot, so the target variable was looking for the Robot node, but the raycast's get_collider() function would often find the SpellHolder node instead, making the following condition fail:

    if raycast.get_collider() == _target:

    Because the SpellHolder covers the top part of the robot, the raycast could only hit the Robot's collision shape from below, which is why you observed it only working when the shield was below the Robot.

  • S
    Sketch Armstrong(Sketch Armstrong) replied

    thank you, I never would have caught that, and now know what to look out for