Search Unity

Coin changes player speed

Discussion in '2D' started by Mixerit, Oct 21, 2019.

  1. Mixerit

    Mixerit

    Joined:
    Oct 21, 2019
    Posts:
    3
    Hi, my question might be easy for you but i started programing in general just yesterday and I want to learn myself, my question is how to make so if a player touches/grabs an object (in my case coin) his speed increases by 20% and then goes down to normal.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi and welcome,

    The overall idea is something like this:

    1. Detect collision with a pickup. Make the pickup a trigger unless you want the player to actually collide with it (if you would use Physics.)

    2. Use OnTriggerEnter to run some code that performs the speed increase.

    3. In your player script, have a speed modifier. Change this speed modifier and apply it's effect to the movement of the character controller or a physics based object your player controlled object is.

    4. In the player script, build a timer which you activate when this pick up event happens. When the timer has expired, disable the effect of the speed up.
     
    Ledesma099 and vakabaka like this.