Final Game #1: Distance, Displacement, Acceleration, Velocity and Gravity

In my final game, I intend to produce a 2D platform style game where the player can flip the gravity, and travel on the floor and ceiling of the game. The basic movement and gravity mechanics will be controlled by the physics mechanics described below.


Distance:
Distance is the measurement of how far apart two objects are. This is calculated by the square Root of (x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2..

In the game, the player can track their progress throughout the level. The counter will help the player work out how far away they are from the end goal. This can be useful if there are different paths to the end goal.



In the script, I take two Vector3 components, and subtract the X/Y/Z axes between each other.
I then get the power of each axis, and get the square root of the values added together.

Formula: SqRt( (x1+x2)^2 + (y1+y2)^2 + (z1+z2)^2 )
Displacement:
Displacement is the motion of moving an object from one position/vector to a second position/vector. It is calculated by subtracting the final vector, from the initial vector.

In the game, the player can change the gravity, a force which pulls the player towards the floor/upwards to the ceiling. When the player changes the gravity, it will change the player's velocity on the Y-axis.

In the Scene view of the level, you can see the red enemy boxes show the displacement.




Acceleration:
Acceleration is the concept of a velocity's change over time. This is calculated by dividing the displacement by time. In my game, the acceleration is used to allow the player to speed up and gain momentum. When the player releases any input/control buttons, inertia will be applied as a resistance to slow down the player.


Evidence of Inertia. The velocity is subtracted from itself, and multiplied by acceleration and time.
The velocity is subtracted to simulate the force in the opposite direction to velocity.

Velocity:
Velocity is the concept of changing an object's position over time. Within my game, all moving objects (player and enemies) are affected by velocity.  Velocity is applied by dividing distance by time taken. The other three physics concepts in this blog post are examples of velocity being applied to objects.


Gravity:
Gravity is a force which causes objects with a mass to push towards each other. The main game mechanic is changing the gravity, so this was a key factor in my development.

The average value of gravity is -9.8m/s, meaning the force goes towards the floor. However, the value of gravity can also change to positive 9.8m/s, meaning the force goes towards the ceiling. The gravitational value will be applied by the player's velocity.

The below image shows the player with a default gravity, then a gravity upwards, then back to the default gravity.


Gravity also applies for moving through the level, including jumping.

This is the Environment script, which controls the gravity for all velocity-changing objects in my games. Gravity is stored as an int

In the player script, I retrieve the value from the Environment script, and it will change the player's velocity when jumping/moving in air.




Comments

Popular posts from this blog

Final Game #4: Conclusion

Final Game #3: Friction Resistance, Momentum and Local Platforms