**Character movement with vectors- Vector Length:**

In this tutorial we are going to find the distance between two characters on the screen. Consider the previous example of Pacman: P and Inky: I . We want to find out the distance from Inky to Pacman.

In Physics, the vector V is represented by an angle and Length. So

and in game development the same vector can be represented in terms of x and y components of the screen i.e. v=(x,y).

The length of the vector V is represented by the symbol |V| . Using Pythagoras principle

So the length

This can be easily achieved in Unity with a predefined function.

1 |
var distance = Vector3.Distance(object1.transform.position, object2.transform.position); |

where Object1 and Object2 are two 3d/2d objects.

Read More