Code (csharp): var target : Transform; function Update () { transform.LookAt(target); } The object doesnt turn. Ideas?
im pretty sure the only things it could possibly be is you dont have the var target assigned in the inspector, or you havent attached to script to a GameObject. Other than that there is nothing that would stop this from working. Oh it could also be I guess if you have an empty scene except for the two objects you are doing this with, it could be that its doing it instantly, so you just don't see it turning. so instead of transform.LookAt(target); you could do transform.LookAt(target * Time.deltaTime * speed); and then you set speed to like 10 or something and you can see it rotating.
LookAt takes a Transform (or Vector3) and looks at it instantly. Multiplying the target by Time.deltaTime or speed cannot be done to a Transform and does not output what you are hoping for from a Vector3. Either something else in your project is also setting the rotation each frame or you are simply not assigning the script correctly.
Ah Dman (as you know) you are right. Wow that was stupid of me, I was thinking that if you didn't do what I was doing then it would look instantly, but it DOES look instantly and it only changes smoothly because the object it is looking at is rotating smoothly. Haha my bad.
To rotate smoothly you should use Slerp: Code (csharp): transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position), rotationSpeed * Time.deltaTime);
hello I am beginner i have problem like u. i flow scripting tutorial from here: http://download.unity3d.com/support/documentation/Images/manual/ScriptingTutorial.pdf and i have same problem for flowing tutorial in page 4 with "lookat " function . my mistake was using point light instead spot light .looks like for point light "lookat" function have no mean. be careful use spotlight instead point light . --------- sorry for my English writing. :mrgreen:
wurks: public void NeedAShower() { //or update void transform.rotation = Quaternion.Slerp(Quaternion.Euler(TargetToLookAt.position.x, -90f,0f), Quaternion.LookRotation(TargetToLookAt.position), 2f * Time.deltaTime); //you just need this code in update and a transform target, make public target and add target and use this to aim at the ting } a little