+91 9591117915 info@pixtell.net

# 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.

# 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}$.

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 :

# Math for game developers – character movement with vectors

Posted By Kirti P

This is the first of the series of tutorials on how to do character movement anywhere on the screen using Vectors. So essentially we are going to learn vectors, which are used everywhere in video games and are very important.

Lets say you have a character (ex Pacman) on the screen and you want to move him across your screen along to the right.

In PHYSICS: We can consider this as the velocity of Pacman. Velocity is represented by $\vec{v}$. The little arrow on top denotes that $\vec{v}$ is a vector. A vector is an angle and a length denoted by $\vec{v}$=(θ, L). A long vector means the character is moving fast and a short vector means the character is moving slow. $\vec{v}$=(θ, L) is the way vectors are represented in physics.

In game development, the above notation for vectors is difficult to store and so we use the x and y coordinates to represent vectors.

In GAMES: $\vec{v}$=(x, y)

If P(x, y) is the current position of Pacman and P’ is the new position, then P’ is the sum of old position and velocity.

P’= (Px+vx, Py+vy)

P’ is now the new position that Pacman needs to go to !

# Math for Game Programmers

Posted By Kirti P

Math is fundamental foundation to successful game development, game design and production. The movement of characters on the screen, the bullets fired from a gun or the simple parabolic jump of Mario is accomplished by Math.

What are the main branches of math used in game development?

• Algebra
• Discrete Mathematics
• Trigonometry
• Calculus
• Linear Algebra
• Applied mathematics
• Some of the most important math used in games.
• Dot Product, Cross Product.
• Scaling Vectors,  Unit Vectors, and Vectors.
• Reflection, Matrices.
• Scalar Manipulation.
• COS,SIN,TAN.

Math in game development is simulated either by the developer or handled by the game engine at runtime.

# Enable Gamecenter Sandbox

Posted By Kirti P

First thing when you start writing games using Gamecenter for iOS platform ( Sadly Apple bluntly rejects all the apps that make use of Google Game Services ) is the sandbox mode for testing your leaderboards,achievements etc…

Several posts on forums and blogs talk about creating a testing account and doing crazy voodoo stuff to get into sandbox mode. Read all that for a while and the ever increasing frustration writing games for the iOS platform was @#$@#$ ..

And yeah, finally went to the Apple site ( a plain and hard to read page which has no styling what so ever to make life harder ) , found out it was easy !

So here are the steps:

1. Uninstall your development build on iOS device
2. Go to Settings -> GameCenter and log out of your exiting account ( click on the email-id and a popup will appear to logout )
3. A small slider below show “sandbox” , enable that !
4. DONOT  login on the settings tab , instead install your development app and login through it when asked for authentication using your normal Apple account ( the one you use for buying apps will do just fine )
5. You should now be logged into GameCenter

We have also noticed that in case you are creating a multi player game using Apple gamecenter API the clients keep disconnecting every one minute or so..

Happy development !