# Angle between player and rocket targetting player.

I’m stuck with the problem mentioned in the question. I thought it’s very easy, but I do something wrong. So I have a rocket which is following the player (edited from Smooth Follow script).

Now, this rocket is dodgeable by the player for a reason, but as it can’t turn enough quickly to the player, it starts to set an orbit around the player and it goes around the player game object. The reason is pretty understandable, the rocket is too fast and it can’t turn with that speed, it stucks around the player.

I want to make the player’s situation more dangerous by slowing down the rocket, when it’s angle relative to the player is too high. For example, if angle is larger than 30, slow down the rocket to follow the player easier, if it is less than 30 again, fly with maximum speed.

Of course, if the player is behind the rocket (rocket is facing the opposite direction), slow down to the minimum speed allowed for the rocket, find the target and again, fly with maximum speed.

What I was trying:

``````angleToTarget = Vector3.Angle(target.position,transform.forward);
``````

It’s in Update() of course.

I guess, the problem is that transform.forward, it is applied in world space, not locally. I need a solution that works in local space. I hope it is understandable, I usually over-complicate things, but… nevermind!

``````  var dot = Vector3.Dot((target.position - transform.position).normalized, transform.forward);
``````  var rocketSpeed = Mathf.Lerp(minimumRocketSpeed, maximumRocketSpeed, Mathf.Clamp01(dot));