+91 9591117915 info@pixtell.net

## Character movement with vectors- Vector Length

Pixtell Labs gamedev, Tutorials Character movement with vectors- Vector Length

# Character movement with vectors- Vector Length

Posted By Kirti P

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
$\vec V=(\theta, L)$
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
$\vec v^ 2=\vec vx^2+\vec vy^2$

So the length

$L=\mid\vec v\mid=\sqrt{\vec vx^2 +\vec vy^2}$

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

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

Tagged