Question by
Blockhead01 · May 30, 2018 at 05:19 AM ·
targetmissilevector3.movetowardshomingtargetrotation
Trying to get missile to home in on player position instead of one fixed position
So right now my missile is homing and tracking just one position but I need it to track the player in real time instead it seems like the missile is only tracking the players starting position.
Here's my code so far:
public Transform target;
public float speed;
void Update()
{
Vector3 targetDir = target.position - transform.position;
float step = speed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f);
Debug.DrawRay(transform.position, newDir, Color.red);
transform.rotation = Quaternion.LookRotation(newDir);
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
Any help would be greatly appreciated.
Comment
Your answer
Follow this Question
Related Questions
how to fire a missile that select nearest enemy to my aim 0 Answers
How do I complete homing missile movement? 0 Answers
Homing missile just rolls toward the player/not floating 2 Answers
Homing Missiles! 1 Answer
Targeting Script Errors 0 Answers