1
\$\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\$
  • 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 '18 at 11:13
  • \$\begingroup\$ "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. \$\endgroup\$ – DMGregory Sep 14 '18 at 15:42
  • \$\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\$ – Big T Larrity Sep 17 '18 at 14:08
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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.