- Home /
How to limit raycast at the edge of platform?
Hi! I'm working on a 2d platformer game and now I'm creating an AI for my enemy. It uses linear raycast to detect if player is there. The problem is, when it gets close to the edge and my player is standing near on another platform my enemy can't tell if there is a gap and it doesn't need to attack my player. I limited attack by detecting a gap while in attack state but still it happens like this:
Enemy gets closer to the edge
Raycast detects my player
Enemy crush!
Enemy detects the edge and turns away.
What I need is to remove "enemy crush" phase if my player isn't on the same platform with this enemy. I'd set some boundaries but it's too much pain in a relatievly huge game, I'd prefer my enemy to handle these kinds of situations itself.
Any suggestions? Thanks for help :)
Your answer
Follow this Question
Related Questions
Rotate with Raycast??? 2 Answers
Raycasting crashing Unity? 3 Answers
Modifying AI script to follow gameobject 1 Answer
Linecast is always blocked. 2 Answers