[EDIT] Messed up with Raycast’s parameters : for direction I put a position, not a true direction == player.transform.position - eyes.transform.position
Instead of just player.transform.position… Noob mistake //END
Hello everyone,
My enemy shoots a raycast from his eyes to the player’s position (cible). It uses a Ray “viseur” (see script).
As you see on the picture, the yellow line, which is the same as the Ray viseur, is correctly oriented to the player.
The cyan line is the hit.point, which is totally abnormally hitting the wall, wrong direction. But the Raycast uses the Ray, so how is that possible??? The enemy is in IgnoreRaycast layer.
I’m lost… Thank you for your help.
if (angle < fieldOfView * 0.5f) //angle between enemy and player
{
Debug.Log("angle is right");
RaycastHit hit;
Vector3 cible = player.transform.position;
cible.y += 2; //adjusting height
Ray viseur = new Ray(eyes.position, cible);
if (Physics.Raycast(viseur, out hit, range))
{
Debug.Log(hit.collider.name);
Debug.DrawLine(eyes.position, cible, Color.yellow);
//this Line is drawn between eyes of enemy and player (cible) position
Debug.DrawLine(eyes.position, hit.point, Color.cyan);
//this line is between eyes of enemy and hitpoint, they should logically be the same
Debug.Log("Raycast fired");
if (hit.collider.tag == "Player")
{
Debug.Log("Raycast touched player");
inSight = true;
chase = true;
agent.speed = chaseSpeed;
}
}
}