DRIFT DRIVING QUEST: ‘Damage System' - Solutions

Quest: Drift Driving Quest
Challenge: Damage System

Feel free to share your solutions, ideas and creations below. If you get stuck, you can find some ideas here for completing this challenge.

I solved this with the following:

  1. Added a new Health Script attached to the CarSphere that contained this code:
    void OnTriggerEnter(Collider other)
    {
    if(other.tag == “Damage”)
    {
    hitPoints += -5;
    print(hitPoints);
    }
    }
  2. Added a new Sphere Collider to the CarSphere and clicked on the IsTrigger.
  3. Added a new tag called “Damage” and added this tag to the outer walls and a few other objects.

Very little answers for this question so I will give my solution.

I created a script on the sphere that manages the Health of the car.

It is linked to a game object that has a TextMeshProUGUI component (to see in the UI the life of the player.
I put tag to all object that could potentially be walls in the game (like ramps, trees, …)

I finally use OnColisionEnter to check if the car hit a “wall” and if it did the velocity of the car. If the car velocity is very small it means we hit a wall and it stopped us. This allow us the take the ramps correctly without taking damage as we have a high velocity!

It’s not perfect as you can still take a ramp super slowly and therefore take damage but I that’s the best I could do (for now :stuck_out_tongue: )

I didn’t do a reload scene or anything when the car “dies”! To be added later

Privacy & Terms