4 mins
The thrid post in making items for mario kart in DirectX12
Implentations of bombs, triple banana peels, and singular and triple mushrooms
The bomb is an item that when used starts a countdown which when finished creates an expanding explosion, hitting all players in it’s radius.
Similar to the banana the bomb uses the in-built item trailing system to follow the player and can be thrown. But when used starts a 4 second countdown until it creates an explosion in the game scene by binding a create explosion function in the bomb class to one in the game scene (similar to how items are created). Once created, the explosion uses a vector lerp to increase it’s scale until it is ten times. Once the lerp is finished, the explosion is set to be destroyed in the game scene. When a player collides with the explosion through the collision manager the player gets launched into the air and flips using the same animation functions as with previous items. When either an item or a player collides with the bomb itself it, the bomb detonates thus creating the explosion.
The triple banana peel works the same as the single banana peel except there are 3 of the them, which trail the player in a line.
To implement this a rework had to be done to the current item system. To start with the trailing item in the player class was changed from a single item pointer to a vector of item pointers. So when triple bananas peels are spawned 3 banana peels are created and pushed onto the vector. Then within the trailing item function this vector is looped backwards through and every item except the lasts position is set relative to the previous item. When an item is released by the player, the first item in the vector is used and popped of the vector. The control scheme is also different for triple items, with the use button being pressed once in order for the items to all trail behind the player and then subsequent times to then use on item at a time. To do this a triple item bool is flagged when the bananas spawn causing which then causes the system to use a different input scheme where the items are constantly being trailed and pressing the use button calls release item.
Initially when triple banana peels spawned in a line behind the player, the collision manager would detect they where intersecting and destroy all three of them. In order to stop this without having to spread the trailing banana peels far apart, a vector of item pointers called immune items was added to the item class. When the triple bananas where spawned they each added their immune item vector to the trailing item vector. Then within the collision manager when checking to see if 2 items are intersecting the current item immune item’s are checked to see if the intersecting item is one of them. If so then the collision was skipped.
Mushrooms are an item that don’t create a mesh when spawned, instead they’re used instantly giving the player a temporary speed boost.
The first implementation of mushroom boost was adding 10 times the player’s nomalised velocity to their current velocity. This was too brief of an increase in velocity however, so instead when the mushroom is used it sets a used flag to true. This is then checked for in the mushroom’s update function so when true adds 30 times the player’s normalized velocity to their current velocity. And since this is called in the mushroom’s update it applies this boost every frame. Lastly, a timer of 40 seconds was added which when the item was used the countdown finished, the mushroom was set to be destroyed in the game scene.
The implementation of triple mushrooms worked similarly to triple banana. When a triple mushroom are initially used by a player they use one mushroom and 2 more are added to the trailing item vector.When the player calls release item one of the mushrooms is used and popped of the vector. The current inventory item is also not removed untill all three mushrooms have been used.
There was an issue with the size of the colliders for the item boxes where they were too small to hit. The colliders were the same size as the mesh but it was hard for players to drive directly into them in order to get an item. To stop this issue I added an addition scale float to physModel which is multiplied to the scale to set the extents of the box collider. I then set this additional scale to 50 in the item box class. Because of this the item box’s colliders where much larger and easier to hit.
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)