[Java]Transform.lookat makes any object rock madly

Hey all, I am currently trying to get my enemy to constantly look at the player like they did in the TornadoTwins tutorial and my script is;

#pragma strict
var player : Transform;

function Update () 
{
	transform.LookAt(player);
}

I know this is right because I did it before and it worked fine, however now its like whatever object I attach this script to freaks out and the object rocks backwards and forwards and its moving so fast that its transparent. I have tested it with multiple models from and outside of unity. Please help and sorry I can’t explain it better. All I want is a simple lookAt script.

On What Object you are using this script? is it a child or something?

thanks for your reply, Nope, its just a cube with a cylinder as a child, the script is attached to the parent.

Thanks! that worked, and it's so weird? I repeated the same process in my scene and it worked perfect :S oh well thank you!

A gameObject named "player" isn't important. In the Inspector, make sure you have the correct thing dragged into the player script slot. Maybe by mistake you're trying to look at yourself.

I guess you didn't created the object for the player or the both game gameObjectsd were not at the correct positions and your welcome c:

1 Answer

1

ehm try making a new scene and create two cubes one with “player” name then place both objects on a plane so you can look at the positions of them then put the script in the other object and Play it. see if it works?