# Rigidbody slows down when its going up a slope. What can I do?

I am using unity and I am creating a 3d topdown game. There is no jump feature. The input handling supports only x and z axis player movement. Climbing slopes or falling from gaps is something I want to happen without certain input.

So, I have a rigidbody which I move by directly setting its velocity. When it goes up a slope it slows down.

I would like it to keep the same speed.

Now I do it like this:

    void Update(){
moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
}

void FixedUpdate(){

MyRB.velocity = moveInput.normalized * runSpeed
}


I am using a capsule collider on the rigidbody and a box collider for the slope. The physics materials of the colliders are the default/none (not changed).

• Can you show us both the code you're using to set the velocity (so we can see whether you're driving it up along the slope or flat into the slope), and the physics material properties you've set on the capsule and box? – DMGregory Sep 14 '18 at 11:13
• "moveinput gets input.getaxisRaw("horizontal") and Vertical in Update()" - we really need to see the exact code you're using for this. There are several ways it might have been implemented, and we can offer different solutions depending on how your current method works. – DMGregory Sep 14 '18 at 15:42
• For me, checking the values for mass and drag in Inspector - Rigidbody, and the amount of force added to the rigidbody upon input allows me to go up slopes etc. – Big T Larrity Sep 17 '18 at 14:08

## 1 Answer

It entirely depends on how you're moving your rigidbody. If you're manually updating the position each frame (using Translate or movePosition, not AddForce), you can apply a physics material to your sphere collider and set the friction somewhere at or slightly below 1. This allows your rigidbody to grip the sloped surface a bit better.