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.
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.
Subscribe to this blog via RSS.
C++ 30
Directx12 11
Mario kart 11
Commercial games development 15
Unity 15
Low-level programming (19) C++ (30) Text based adventure (5) Ex-machina (9) Game engine programming (11) Directx12 (11) Mario kart (11) Land of gold (5) Audio visual production (1) Commercial games development (15) Unity (15) Don't walk by (15)