3
\$\begingroup\$

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).

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 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? \$\endgroup\$
    – DMGregory
    Sep 14, 2018 at 11:13
  • \$\begingroup\$ 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. \$\endgroup\$ Sep 17, 2018 at 14:08

1 Answer 1

0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .