Question by
NFonseca101 · Oct 01, 2016 at 06:57 AM ·
rotationquaternioneulerangles
Quaternion.LookRotation on only one axis?
Quaternion look = Quaternion.LookRotation(player.position - transform.position); transform.rotation = Quaternion.Euler(look.eulerAngles.x, 0, 0);
I simply want my object to look at the player object only on the X axis. Try the script out yourself. Once it gets to 90 degrees it stops trying to look towards the player object.
Comment
Answer by JedBeryll · Oct 01, 2016 at 07:03 AM
Easiest way I can think of is to bring the target point to the level of the transform on y and z. I haven't tested it so does this do any good?
Vector3 target = new Vector3(player.position.x, transform.position.y, transform.position.z);
transform.rotation = Quaternion.LookRotation(target - transform.position);