# How do I increase the speed of my rigidbody after going down the slope

So, right now, I’m trying to create a slide and I want to so when I slide down a slope, my movement speed builds up then it continues even after I finished sliding, basically, that increased movement speed will be applied to my walking and sprinting and all that, but I want to limit my movement speed and decrease my speed overtime after I finished descending the slope, sorry this is pretty hard but I really can’t think of a way to do it. @Llama_w_2Ls I tried your method but it didn’t work, I did (rb.velocity.magnitude < max speed) {rb.velocity += maxspeed}, but it wasnt working and was giving me an error says something about Vector3 and floats. Thanks to anyone who will try to help me.

how are you detecting being on the slope? ontriggerenter? if so, do OnTriggerEnter(Collider other){
if(other.tag == slope){
rb.velocity += maxspeed

}
else{
rb.velocity = normal velocity
}
}

@Llama_w_2Ls do I share both my movement and camera script and you try to find the issue?

public CharacterController controller;

``````    public float Walkspeed = 6f;
public float Runspeed = 12f;

public float gravity = -9.81f;

public Transform GroundCheck;
public float GroundDistance = 0.4f;

public float JumpHeight = 3f;

Vector3 velocity;
bool IsGrounded;

float Maxspeed = 20;
float SpeedIncrease = 0.05f;
public bool OnSlope = false;

// Update is called once per frame

void Update()
{

if (IsGrounded && velocity.y < 0) //fall
{
velocity.y = -2f;
}

float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");

Vector3 move = transform.right * x + transform.forward * z;

if (Input.GetKey("w") || Input.GetKey("s") || Input.GetKey("d") || Input.GetKey("a")) // Walk
{
controller.Move(move * Walkspeed * Time.deltaTime);
}

if (Input.GetKey("w") && Input.GetKey("left shift") || Input.GetKey("s") && Input.GetKey("left shift") || Input.GetKey("d") && Input.GetKey("left shift") || Input.GetKey("a") && Input.GetKey("left shift")) // Run
{
controller.Move(move * Runspeed * Time.deltaTime);
}

if (Input.GetButtonDown("Jump") && IsGrounded) // Jump and gravity
{
velocity.y = Mathf.Sqrt(JumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);

if (OnSlope == true && Walkspeed < Maxspeed)
{
Walkspeed += SpeedIncrease;
controller.Move(move * Walkspeed * Time.deltaTime);
Debug.Log(Walkspeed);
}

else if (OnSlope == false && Walkspeed > 6)
{
Walkspeed -= SpeedIncrease;
controller.Move(move * Walkspeed * Time.deltaTime);
}
}

private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Slope"))
{
OnSlope = true;
}
}

private void OnTriggerExit(Collider other)
{
OnSlope = false;
}
``````

My entire movement script + running when pressing shift + increasing walking speed when on a slope. You need to assign the script to an object (eg. capsule) that is parented to an empty gameobject with a character controller. The Parent should also have an empty gameobject under its own feet as a ground check, as well as a layer set to all objects that you can walk on (e.g. ground), which is the layer of the layermask. This FPS controller was set up by Brackeys, with some custom scripting for slope sliding. If anyone is interested in wall running, i can send my script for that as well.