I am working on enemyAI in which the enemy is on a patrol but engages the player when they are within certain area.
However because the center of my character is lower than the enemy the enemy tries to look down on the floor as i have transform.LookAt(target); telling it to. This makes it act a bit crazy.
Is there a way to use transform.LookAt(target); but specify it to only do so on the Y axis and not the X so it doesn’t look down at the floor.
function LookAtIgnoreHeight (target : Transform) {
var lookAtPos : Vector3 = target.position;
//Set y of LookAt target to be my height.
lookAtPos.y = transform.position.y;
transform.LookAt (lookAtPos);
}
That should be what you need.
Please confirm if that works for future consultations.
I fixed this in the end, it was complicated but in short ‘blacktear’ was correct.
I had to two different lookats into the two different states of my enemy. When the enemy is moving toward the waypoints then transform.LookAt(target); was fine