Featured Blog

How to Create Homing Missiles in game with Unity

The main objective of this post is to give a brief introduction to Homing Missiles in Game (2D). A script for Homing missile is also included and explained in the article.

Create Homing Missiles in game unity tutorial


The main objective of this post is to give a brief introduction to Homing Missiles in Game (2D). A script for Homing missile is also included and explained in the article.

What is a Homing Missile?

What is the logic behind Homing Missiles?

How to use Homing Missiles in Unity?

Have these Questions in Your Mind?

No worries. You will get a satisfactory answer to all those questions, right here.

Let’s start with Introduction


You might have seen Homing Missiles in movies.

Real life example homing missile

Remembered these scenes from “Marvel’s The Avengers” movie?

If you are not a Marvel fan don’t worry, I am here to help.

Homing Missile is the missile which locks target and chases the target until or unless it reaches the target and blasts itself.

There are plenty of games which are using Homing Missiles.

Excited to implement Homing Missiles in your game?

I know you are.

Let’s set the scene first

Scene Setup:

  1. Create two 2D Objects name them “Missile ” and “Target”.
  2. Add a Sprite to them. (You can download the project from below link).
  3. Add rigidBody 2D in missile and add Script also name it as ”Homing Missile”

How it actually works?

You might think It is easy to Implement Homing Missile. Just use MoveToward/Lerp until it reaches the target.

Just write code and look at what is going on in your scene.(First try and then read further to understand)

working of homing missile

It is reaching the target properly but there is no feel of a rocket. (Right Brain:-What is wrong with my code!)

Below is an actual script for Homing Missiles.


    public class HomingMissile : MonoBehaviour
        public Transform target;
        public Rigidbody2D rigidBody;
        public float angleChangingSpeed;
        public float movementSpeed;
        void FixedUpdate ()
            Vector2 direction = (Vector2)target.position - rb.position;
            direction.Normalize ();
            float rotateAmount = Vector3.Cross (direction, transform.up).z;
            rigidBody.angularVelocity = -angleChangingSpeed * rotateAmount;
            rigidBody.velocity = transform.up * movementSpeed;

I think script is short but not a sweet one. You can use this homing missile script for your code.

Don’t be scared, I’ll show you how to do it.

Let’s start with the table to introduce variables:

Variable Name Variable Type Description
rigidBody RigidBody2D rigidBody of the missile to add velocity and change angle.
target Transform To get the position of the Target.
angleChangingSpeed float The speed to change the angle
movementSpeed float Speed of movement


->Pure Mathematics: (Open your Brain’s left part)

Actual path of homing missile

You need to understand this Picture. That’s How our Homing Missile Works.

First, what you need is “Direction”.


direction= targetPosition (target.position) - missilePosition(rb.position);

vector substraction

This is how subtraction of two Vector happens (Pythagoras Theorem).



Normalization means converting vector to unit vector.


    Vector A(3,4)
    Normalized(A)=(3/3*3+4*4 , 4/3*3+4*4)=(3/5,4/5)


Find Amount of rotation to do that.

    float rotateAmount=Vector3.Cross(direction,transform.up).z;

vector cross product

Blue Arrow(direction)

Red Arrow(Missile Transform)

green(Resulting Vector).

All three Vectors are perpendicular to each other.that’s why we needed z-axis only.


Now we need to change angularVelocity of our rigidBody.

rb.angularVelocity = - angleChangingSpeed * rotationAmount.

Minus Sign(-) is used to reverse the direction of movement.


Adding Velocity to our rigidBody.(just changing the Angle is not Enough).

rb.velocity=tranform.up * movementSpeed.

Stop cheering just yet! This is not the end! Missile needs balancing between angleChangingSpeed and movementSpeed.

What if there is no balance between angleChangingSpeed and movementSpeed (Great question! Open right brain is needed here ! )

missile heading to the target

In the above Image , the missile is heading forward to the target, there is no problem here.

velocity force vs angular velocity

In the above Image, the target has moved to a new position. The missile continues to go toward the target due to angular velocity (in red) , while still going to the place where the target used to be (in black) due to its velocity. (Thinking what is wrong.?)

velocity force vs angular velocity 2

In the above Image, the missile's velocity forces it to move at the side of the target (black) while the angular velocity tries to pull the missile to the target. (Now you might feel there is something suspicious).

orbit dead loop

In the above Image, the missile falls into a stable orbit around the target and never reaches its goal.

The black arrows indicate a velocity vector while the red lines indicates angular velocity. (That’s why need a balance between angleChangingSpeed and velocity).

Considering that there is no friction in space, there is nothing to slow the velocity of the missile down and collapse the orbit.

That is how whole Universe is trapped (Thank God for this error else there is no life!).

Now, How to Fix this Problem ?

Well, There is no particular formula to balance them, but by Increasing angle or decreasing velocity will help you there.


  • Don’t go with very small speed so your missile loses the feel of Homing Missile and Don’t make it Extreme fast it will be trapped in the orbit.


  • Don’t make angleChangingSpeed too small else it will fall in to trap and to high angleChangingSpeed loses the feel of your game.

That’s It for Homing Missile. Hoping to see homing Missiles in your game!

Please, do Share our blogs with others if you like our content :)

Originally published at TheAppGuruz - Mobile Game Development Company on May 31, 2018.

Latest Jobs

Manticore Games

San Mateo, California
Senior Software Engineer - Mobile

Sony PlayStation

San Diego, California
Sr. Online Programmer

The Walt Disney Company

Glendale, California
Associate Marketing Manager - Walt Disney Games

Insomniac Games

Burbank, California
Accessibility Design Researcher
More Jobs   


Explore the
Subscribe to
Follow us

Game Developer Job Board

Game Developer Newsletter


Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Follow us


Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more