Hey, I’m trying to get some AI to work as it should, and my problem is this;
When they enter a trigger collider attached to their head if it is an enemy, they’ll notice them (working)
Then, they should look directly at the player (not working.)
I’ve done a few things to debug this, and I’ve come to some interesting conclusions;
They do not look directly at the player, and albeit it should be precise and all that it isn’t.
I’m going to post some of my code
void Face_Task()
{
if ( task_obj == null )
{
return;
}
Vector2 toForward = Target_Direction();
transform.forward = new Vector3(toForward.x, 0, toForward.y);
return;
}
bool Facing_TObj()
{
if ( task_obj == null )
{
return false;
}
Vector3 targeting_direction = Vector3.Normalize (transform.position - task_obj.transform.position);
if ( Mathf.Abs (transform.forward.z - targeting_direction.z) < .1F && Mathf.Abs (transform.forward.x - targeting_direction.x) < .1F ) // Not sure if this is the best.
{
return true;
}
else
{
return false;
}
}
void Aiming_Funcs()
{
if ( task_obj == null )
{
Current_Task = Task.None;
return;
}
else
{
Face_Task();
if ( Facing_TObj() )
{
if ( dispersion < .3F )
{
// For actual firing.
Face_Task();
return;
}
}
else
{
}
return;
}
}
Also, it does not pass Facing_TObj() so nothing below it gets called, so I also know by that it actually isn’t facing the technical forward. And GameObject task_obj is the player, which I know is assigned right. It would seem to be that the player object is not centered properly, and granted that could be it but even so, it isn’t that off center. So I can’t imagine it’s that much of the problem.
After looking closer and testing it in-game, it also appear they look at the person’s right on the x or z axis.