S
SacralWolfChapel

About Area2d AND RayCast

On the bat, why do we have both an Area2D and a RayCast2D that both detect the player? Wouldn't just the raycast suffice?

  • godoterfr replied
    The Area2D is the "possible" assault range. For the aggression to be triggered, the Raycast2D must have a direct view of the player. Basically, the Area2D is the reach your arm has. And the Raycast2D is the direction of your eyes. Someone may be within arm's reach, but if they're behind you, you won't see them.
    2 loves
  • Nathan Lovato replied

    As godoterfr explained, they serve different purposes. The ray cast serves as a way to test the line of sight to the target, and the area node controls the area in which the mob considers potential targets.

    You can try with just a ray cast, you'll quickly see it's harder to code this without the area,

    1 love
  • S
    SacralWolfChapel replied

    Okay, I see. I figured they'd have different purposes, just wasn't clear to me. Thanks!