+91 9591117915 info@pixtell.net

Character movement with vectors- with two characters

Pixtell Labs gamedev, Tutorials, unity3d Character movement with vectors- with two characters
Character movement with vectors- with two characters

gamedev Tutorials unity3d

Character movement with vectors- with two characters

Posted By Kirti P

Character movement with vectors- with two characters:

In the previous section we learnt what a vector is and how to move a character P (eg Pacman) from its current position to the new position.

In this section we will introduce a new character I (eg Inky). Lets say we know the Pacman’s position and Inky’s position and we want Inky to eat Pacman. So essentially we need to find a vector from Inky to Pacman. We call this vector \vec{v}.

TUTORIAL-2

The vector that will take us from Inky to Pacman is \vec{v} = P-I  i.e. Pacman’s position minus Inky’s position. In terms of individual x and y components, V(x,y)= (Px-Ix, Py-Iy).

It is really important to know that P comes first and I next so we get a vector from I to P.

In Unity 3d Engine we can find the direction vector using the following code snippet :

 

 

Tagged

Leave a Reply

Your email address will not be published. Required fields are marked *