How to make platforms where the car moves faster?

Hey guys! I am making a 2D car game (like Hill Climb Racing) and I make use of the Weel joint stuff. I already got the basic movement and added jumping but now I want some platforms where my speed increases. I don’t really know how to do it so that’s why I wanted to ask you if you can help me out :slight_smile:
That is my current code:

    public Rigidbody2D carRb;
    public Rigidbody2D backTire;
    public Rigidbody2D frontTire;

    [SerializeField] private float speed;
    [SerializeField] private float jumpSpeed;
    [SerializeField] private float carTorque;

    private float movement;

    // Update is called once per frame
    void Update()
    {
        movement = Input.GetAxis("Horizontal");

        if (Input.GetButtonDown("Jump"))
        {
            carRb.velocity = new Vector2(carRb.velocity.x, jumpSpeed);
        }
    }

    private void FixedUpdate()
    {
        backTire.AddTorque(-movement * speed * Time.fixedDeltaTime);
        frontTire.AddTorque(-movement * speed * Time.fixedDeltaTime);
        carRb.AddTorque(-movement * carTorque * Time.fixedDeltaTime);       
    }

Assuming you want to create a “boost” modifier like in mario kart, you can create an empty gameobject with a collider set to trigger and configure it’s size and position to define a zone.
Add a script called MyModifier on the empty object that does something like this:

[System.Serializable]
        public class MyModifier : MonoBehaviour {
            public enum ModifierTypes { SpeedUp, SlowDown, Fly, Explode, Etc }
            public ModifierTypes type;
            public float value;
            public float duration;
            public System.Guid GUID;

            Awake() {
                GUID = System.Guid.NewGuid();
            }
        }

In your car’s controller script (or wherever you feel is appropriate) add something like this:

        List<MyModifier.ModifierTypes> activeModifiers = new List<MyModifier.ModifierTypes>();
        private void OnTriggerEnter(Collider other) {
            var myModifier = other.GetComponent<MyModifier>();
            if (myModifier != null && activeModifiers.Contains(myModifier.type) == false) {
                activeModifiers.Add(myModifier.type);
                StartCoroutine(ExpireModifier(myModifier))
                switch (myModifier.type) {
                    case MyModifier.ModifierTypes.SpeedUp:
                        SpeedChange(myModifier.value, myModifier.duration);
                        break;
                    case MyModifier.ModifierTypes.SlowDown:
                        SpeedChange(-myModifier.value, myModifier.duration);
                        break;
                    case MyModifier.ModifierTypes.Fly:
                        Fly(myModifier.value, myModifier.duration);
                        break;
                    case MyModifier.ModifierTypes.Explode:
                        NukeIt(myModifier);
                        break;
                    case MyModifier.ModifierTypes.Etc:
                        break;
                        SkyIsTheLimit(myModifier);
                    default:
                        break;
                }
            }
        }

        IEnumerator ExpireModifier(MyModifier modifier) {
            if (activeModifiers.Contains(modifier.type)) {
               yield return new WaitForSeconds(modifier.duration);
               activeModifiers.Remove(modifier.type);
            }
        }

Fell free to add some artwork, to the modifier game object to represent it in game, but make sure it doesn’t have an additional collider or your car will hit it instead of going through.
Also, make sure you have the following on top of your script or some classes won’t me accessible:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

Good luck.

You can use collisions
just set the platform’s tag to hit

public float speed = 5;

public float defaultspeed = 5;
public float hitSpeed = 7;

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.tag == "hit")
    {
        speed = hitSpeed;
    }
    if (collision.gameObject.tag != "hit")
    {
        speed = defaultspeed;
    }
}

I hope this works