The Desired solution is quite simple. To have my enemies turn to face me the player.
The code is simply
function start()
{
if (target == null GameObject.FindWithTag(“Player”))
target = GameObject.FindWithTag(“Player”).transform;
}
function update()
{
transform.LookAt(target);
}
The problem When i use Transform.LookAt my enemies (who are taller than my player for the games sake)will turn on their X and Y axis to fire at me. I only want them turning on their Y axis.
However After staring at the Code for a few hours and trying random things to try and get the desired effect I have come to no avail.
target.position.x and target.position.z
means look at that position(player position) without the height parameter(y axis).
transform.position.y
means to never look up or down of your current position
if the player is at position 4, 5, 6(x, y, z) and the enemy is at 0, 2, 1 the enemy will look up if you use transform.LookAt(target); (wich is the same as transform.LookAt(Vector3(target.position.x, target.position.y, target.position.z)) and transform.LookAt(Vector3(4, 5, 6))) but if you use transform.LookAt(Vector3(target.position.x, transform.position.y, target.position.z)); the transform.position.y parameter means to look at his current Y axis wich is 2 in this case (the enemy will look at (4, 2, 6)).