- Home /
transform.LookAt causes my object to explode
I am following a simple tutorial to learn Unity- in the tutorial, I am attempting to make a turret who's head always rotates to follow the player's location. The script is the one from the Unity Script Reference:
var target : Transform;
function Update() { transform.LookAt(target); }
This script is used in the tutorial, and works great for them. But, when I use it (or the SmoothLookAt script that comes with Unity), applying it to the part I want to rotate (the turret head) and targeting my character (the worm), the turret head flies off to a seemingly random location and orbits around my character as I move it. Any ideas?
For reference, the tutorial I am following can be found here: http://www.youtube.com/watch?v=u8t3fdKhDxg&feature=relmfu and the relevant script and application are at 7 minutes in. Any help would be greatly appreciated!
Answer by Jason B · Oct 13, 2011 at 10:49 PM
Is the head of your turret parented to anything?
Yeah, make sure your turret head is parented to the body.
That did it! Thanks! I will understand this, eventually. :)
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Rotate One Object Around Another 1 Answer
Lock rotation axis? 4 Answers
Look At objects using a SNAPPED angle 2 Answers