Global Gravity Flip and Jumping

Global Gravity Flip and Jumping

Feb 2, 2019. | By: Evan Diamond
1 min

The next part of the physics is to for the player to have an ability that can invert the world’s gravity along with jumping in the correct direction.

Gravity Invert === To start with a gravity direction int was put into the Game Scene’s header file, this value was then passed into every object in the scene that had a physics component. This value was used to termine the direction of the weight of the object which was used to apply gravity, moving the sprite down the screen unless it was in contact with something.

When the user presses q and has the gravity invert ability then a invertGravity function in the player’s physiscs component is called which takes the gravity direction by ref and sets it to iteself * -1. This then inverts it and changes the gravity direction of everything in the scene.

Jumping

When the user presses space to jump a jump count float is set to 1 in the physiscs component. The y position of the player is then moved by the -gravity direction * jump count * jump force. Then whilst each frame of the game where the jump count > 0 it is reduced by delta time thus reducing the amount the player is moved by the jump. Eventually the gravity force still acting on the player will be stronger than the amount the player is jumping by and the player will fall to the ground.

About

Gamers developing new games.

Social Links

Our Bunker

University of the West of England,
Frenchay Campus, Bristol, BS16 1QY,
United Kingdom.