Mario Kart Item Post 8
Overview
Red shells and collision manager config
Red Shells
Red shells are a common item in Mario kart. When used they target a player and drive along the track. Once within a certain distance of the player they move towards them and try and collide with them. If they hit a wall or another item they’re destroyed.
When used the red shell class’s velocity is set to the using player’s normalised velocity and multiplied by the movement speed of the shell. If the shell’s alternate use is being used it sets its velocity to negative the players and does not use ai. This makes the shell go backwards from the player and is destroyed when it collides with an item, player or wall (this happens in Mario kart too). If alternate use is not used then red shell ai’s waypoint is set to the players current waypoint and it finds its target player. To find the shell’s target player all the players are passed into the red shell class on construction as a vector of player pointers. When the shell is used this vector is then searched to first of all check any player’s who have a greater or equal rank of the using player (player’s behind in the race). Next, it checks to see if the target player pointer is nullptr if so then the target player is set to the current player. Otherwise, the current player’s ranking is checked to see if it is greater than the target player, if so then the target player is set to the current player. If no target player is found then the players are searched again until the player with the lowest rank that isn’t the using player is found. The target player is then set to this. Once the target player is found the player vector is cleared.
Once the item is used and the target player is found the red shell’s update function calls the ai’s update function. This is until the distance squared between the red shell and its target player’s position is less than a certain threshold (stored in the item config JSON). At this point, the red shell deletes its ai and does and creates and moves towards the target player using a move towards vector. This vector is made by finding the difference between the target player and the red shell’s positions, normalising it and multiplying by the red shell’s speed. This vector was originally made once but rarely hit its target, so instead this move towards vector is calculated every frame until it is destroyed.
Collision Manager Config
Some parts of the collision manager still had hardcoded values such as the minimum distance square between physmodels before they’re checked to be intersecting (recently added) and the collision response data when an invincible player collides with a non-invincible player. No deal with these hardcoded values they have been added to a collision manager config JSON file.