- Home /
lookAt on Y axis only
i know this question has been asked before but i didn't work in the script i'm using, i need the transform variable "turret" to look at the transform variable "target" only on the Y axis based around the current script part i'm using:
turret.transform.LookAt(target);
thanks :)
Answer by hathol · Jun 29, 2012 at 05:35 PM
maybe not the most efficient, but a working solution:
Vector3 eulerBefore = turret.transform.eulerAngles; // or localEulerAngles, dependent on your needs
turret.transform.LookAt(target);
eulerBefore.y = turret.transform.eulerAngles.y;
turret.transform.eulerAngles = eulerBefore;
thanks $$anonymous$$, i just had to change the vector3 at the start to var as it came up with an error but it works a charm... thanks!
no problem :) I usually write my scripts in c#, therefore the Vector3.
Your answer
Follow this Question
Related Questions
Lock rotation axis? 4 Answers
Lose connection to dragged variable when making prefab 1 Answer
Look at object when it is in the range of the player 0 Answers
Find Transform in the scene 2 Answers
iTween MoveTo with LookAt 1 Answer