How do i make speed shoes ?

Hello i don’t know how to code and i’m making a 2d game. I wanted to make power ups like the speed shoes from sonic. Can anyone post a code and then i paste over ? with explenation of course.

just need to add +x to your speed

1 Like

Yes but how ? and for a limited time ? I said i dont know how to code

How ?

ok first you need to learn how to make your character walk then

you cant learn how to walk faster if you dont know how to walk

i already made the scripts for walking and jumping etc

I just made the scripts while looking at a tutorial

ok can you post them?

ok

5957033–638549–Movement.cs (836 Bytes)
7615270–946423–CharacterController2D.cs (4.58 KB)

here, i made an example, you can press R to gain the powerup

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

public class Movement : MonoBehaviour {
   
    public CharacterController2D controller;
    public Animator animator;
   
    public float normalRunSpeed = 40f;
   
    float horizontalMove = 0f;
    bool jump = false;

    public float powerUpSpeed = 40f;// extra speed granted by power up
    public int powerUpDuration = 200; // how long your power lasts
    public bool hasSpeedPowerUp;
    public int powerUpTimer;
    public float combinedSpeed;

    // Update is called once per frame
    void Update() {

        //Press "R" to activate powerup, you can change this condition to gain the power up in another way
        if (Input.GetKeyDown(KeyCode.R))
        {
            hasSpeedPowerUp = true;
            powerUpTimer = powerUpDuration;
        }

        ///Timer to remove power up
        if (powerUpTimer<0)
        {
            powerUpTimer = 0;
            hasSpeedPowerUp = false;
        }

        //Increase speed if you have power up
        if (hasSpeedPowerUp == true)
        {
            combinedSpeed = normalRunSpeed + powerUpSpeed;
            powerUpTimer--;
        }
        else
        {
            combinedSpeed = normalRunSpeed;
        }

        horizontalMove = Input.GetAxisRaw("Horizontal") * combinedSpeed;
       
        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
       
        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
            animator.SetBool("IsJumping", true);
        }
       
    }
   
    public void OnLanding ()
    {
        animator.SetBool("isJumping", false);
    }
   
    void FixedUpdate ()
    {
        // Move our character
        controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
        jump = false;
    }
}

Cool ! I’ll try it now ! After that, can you try like : Its an object and when the player touches the object it gain the speed and when the timer is out then you lose the power up

yes for that you need to check tutorial on how to make items.

Then when you touch item you can trigger this code

Cool ! I tested the code when pressing R works ! And yes i will check tutorials… thanks !

1 Like