Question by
NoahzArk_127 · Oct 19, 2020 at 09:34 AM ·
aipathfindingraycasthit2dtop down shooter
Ai Destinations not changing when using length of raycast,
im using A* Pathing Project for pathfinding and im trying to make a script that changes the AI Destination Setter target based on the player distance from the enemy using raycast and it just doesnt change the target no matter how far i am from the enemy it just always set to player
//draws a raycast from enemy to play
RaycastHit2D hit = Physics2D.Linecast(transform.position, gb.transform.position);
Debug.DrawLine(transform.position, gb.transform.position, Color.green);
//measures the range of the raycast
if (hit.distance <= range)
{
//sets the Ai Destination Setters target to the player if the
//distance of the raycast is below a ceratin amount
refScript.target = gb.transform;
}
else
{
//if its higher then the amount then it will be set to no target
refScript.target = null;
},
Comment
Your answer
Follow this Question
Related Questions
Enemy pathfinding script for a 2D top down shooter game 0 Answers
My Raycast2D doesn't work properly 0 Answers
Raycast2D don't hit anything below 0 Answers
Can no1 help me??? 1 Answer
Attach a vehicle to multiple paths? 0 Answers