Adding cars to the game


CAR ADDITION SYSTEM

Hello! I’m Gab, in this devlog I’ll discuss the car implementation system and how easy adding new cars to the selection pool is.

First we need to address what a “CAR” is in our game, a car in our game has to have these components for it to be able to be added to the pool:


  • Models
    • Body : the main body of the car with its own materials etc
    • Wheels (optional): wheels are not necessary for the car, but if it does have wheels they need to have a script for the drifting effects (later described in the code section)
    • A “forward” point: the car model must be oriented towards what unity defines “forward”, this caused some issues

   

  • Code
    • Shooting script: this is the code that “spawns” bullets, allowing the players to shoot, this code has a series of values for adding “effects” to the bullet which will be given by the player powerups, some of these values are: bullet speed, bullet size, max bounces, bullets per shot (how many bullets spawn each shot) etc. The shooting script also contains a reference to the bullet prefab. 
    • Kill Car Script: this code is used during the car selection screen to “delete” the care before showing the new one in the list.
    • General Car Stuff: although the name might make it seem unimportant, this code is what handles all of the Aesthetic components of the cars, it handles the animator component of the car which animates the cars when drifting. It also “breaks” pieces of the car as the player health decreases, this is done really easily by dragging and dropping pieces of the model in the Breakoff list, this creates a copy of the object, adds a rigidbody to it and makes it fall off the car while deleting the original piece, making it look like it broke off.
    • Trail Code: this code is attached to specific wheels on the car model (which wheel depends on which would be the “traction” wheels of the car), this creates a game object with a line renderer that follows the wheel as long as the player is drifting creating what looks like a drift mark on the floor, as soon as the player releases the drift button the line object gets “de-childed” from the wheel, making the line renderer stop following the car. The trail also has a space for adding a particle effect such as smoke, this can be easily changed as well.

  • Animator
    • The animator uses the same set of animations for all of the cars, although they might need some tuning when importing the models for the first time into the game, the process is incredibly easy and it automatically sets up the animations to the player actions

Now that we have established what a car is, we can add one to the pool. This can be done by simply creating a new scriptable object of type “car data” in the editor, the scriptable object is composed of:

  • Car name: the name of the car.
  • The model prefab: the prefab we just created with model, code and animator.
  • Speed and turning speed: originally the cars would have had different stats, this was scrapped during development, making these values obsolete and set to a specific value.


Once the scriptable object has been created, we can easily add the new made car to the player prefab car list, this will add it to the pool of cars that the player is able to choose from. The player prefab "wears" the car model by childing it to itself, this is why it's so easy to swap cars without altering the entire prefab. 

In the video we can see a sped up process of me adding the rest of the cars to the pool, adding their animations and making sure that each one worked while also tuning sizes, positions etc.

 CONSIDERATIONS

I’m really proud of how this system turned out, adding cars is easy and fast as long as you have the models and i think this really helps the creativity of the artists. Although having the code for shooting on the actual model might not seem like most intuitive idea, I think it works well for “delegating” actions between objects an not have everything on a single one. Something that might be annoying is that the colliders for hit detections are not on the actual model, which means that some hitboxes might look funky when in game, although this creates a unplanned balancing feature that makes every car have the same hitboxes which is not necessarily a bad thing

Get E-Racer