Im trying to make an enemy that acts like a peashooter.More or less stays in place and doesnt shoot until it spots the player in its line of sight. but for the life of me i cant find a tutorial where it doesnt follow the player around with raycast. is there anyway that i can make an enemy have a static line of sight and shoots in a single line?
Staying in place should be done pretty easily, as it’s basically done by doing nothing. Place your enemy, do not add any movement behaviour, and you’re good to go.
Line of sight can indeed be done with a raycast, but you can cast a ray towards a given direction, not towards the player. That way, you cast a ray, and if you detect nothing, you do not shoot, however, if you detect the player (or anything the enemy should shoot at), you fire a bullet.
I don’t know how detailed you want the explanations to be, so feel free to tell me if that’s enough for you to start building something or not!
You can use Area2D to detect when the player is within range and start shooting.
If you expect there to be any obstacles between the player and the peashooter that should prevent it from shooting, then you’d need a Raycast to check for that. But if you don’t want to prevent the shooting, you can skip the Raycast.