- Home /
Make LookAt only rotate X Axis
I have this script:
static var health : float = 1000.0; var player : Transform; var speed = 5.0; var chaseRange = 50.0; var dieRange = 5.0; private var controller : CharacterController;
function Start() { controller = GetComponent(CharacterController); }
function OnGUI() { GUILayout.Label("\r\n\r\n\r\n\r\nHealth:" + health); }
function Update() { if (player == null) return;
var range = Vector3.Distance(player.position, transform.position);
if (range <= dieRange)
{
health = health-5;
if (health == 0 || health < 0)
{
Destroy(player.gameObject);
}
}
else if (range <= chaseRange)
{
transform.LookAt(player);
var moveDirection : Vector3 = transform.TransformDirection(Vector3.forward);
controller.Move(moveDirection * Time.deltaTime * speed);
}
}
And I want to make the "Tiger" only rotate X axis, because when it starts to follow me it be kinda strange.
Answer by ScroodgeM · Aug 05, 2012 at 06:43 PM
just reset y-component of look direction...
Vector3 lookAtPosition = player.position; lookAtPosition.y = transform.position.y; transform.LookAt(lookAtPosition);
Your answer
![](https://koobas.hobune.stream/wayback/20220613074838im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
AI Look at X axis more efficient code 1 Answer
RigidBody LookAt object in Y axis using AddTorque 0 Answers
How do I make the character look at the mouse? 0 Answers
Zombie AI Help 2 Answers
AI navigating all 6 sides of a cube 0 Answers