- Home /
LookAt fails at close range.
Hello, I am trying to get a missile to work in a 2D game. Normally I thought this would work, but it does not seem to.
I am just using transform.LookAt(target) to make the missile follow the enemy. But if the enemy is rotating a lot. It almost "loses interest" and stops moving and targeting. It usually happens when the missile is close.
Any ideas? var target : Transform; var speed : float = 20;
function Update () {
transform.Translate(Vector3(0,0,speed)*Time.deltaTime);
if(target){
transform.LookAt(target);
}
}
Turns out that the rigidBody was the culprit. It was adding some kind of drag when the missile turned sharply.
It worked better to use rigidBody.velocity..
Answer by senad · Apr 04, 2012 at 08:44 AM
The only thing that comes to my mind is to maybe swap the two lines to make the missile first rotate (look-at) and then move.
Right now your rotation is always one frame late, depending on your stepsize and how much the target moves, there might be some funny artifacts when you get close to the target.
Another thing that might happen when you get close to the target, you might overstep and not notice it. This my result in being further away from the target then before.
So try swapping the two statements and playing around with the stepsize/speed value.
Your answer
Follow this Question
Related Questions
Lock rotation axis? 4 Answers
LookAt Problem 1 Answer
Transform.LookAt Function Customizations... 1 Answer
Hello, Need some help with Enemy facing the player on z axis !! 0 Answers
hoe to rotate a AI as a animation 1 Answer