- Home /
Moving up and down (in a slope) without change to velocity or "bumping"
Maybe I'm using the wrong terminology, but here goes anyway.
I have a player object. It's a capsule with a Rigidbody (use gravity on, Freeze Rotation Constraints on X and Z), a Box collider (size 1, 2, 1) and a player script created by me (below).
Every time I get the player to go over a "pad" (also below), it "stops" a little bit on the edge, losing some speed in the process. The pad has two mesh colliders attached to it (one for the "outer" part, another for the "inner" part).
I'm wondering how I could achieve a behaviour that allows my player to board the pad without losing any speed (to the physics geeks - like myself: I know that, since there is a slight slope, the velocity in the plane will change a little bit. That's not my point. I'm talking about the modulus of the velocity vector).
Here's the pad I made (feel free to grab it and use yourself):
Full assets: https://www.dropbox.com/sh/wgyx356lh9e53fr/_aI5Amsb1F
Here's the movement part of the player script:
function Update () {
var x : float;
var z : float;
if (Input.GetButton("Horizontal")) {
x = Input.GetAxis("Horizontal");
moveX = true;
}
else {
x = 0;
moveX = false;
}
if (Input.GetButton("Vertical")) {
z = Input.GetAxis("Vertical");
moveY = true;
}
else {
z = 0;
moveY = false;
}
if (moveX || moveY) {
if (x > 0) _x = 1;
else if (x < 0) _x = -1;
else _x = 0;
if (z > 0) _y = 1;
else if (z < 0) _y = -1;
else _y = 0;
var movement = Vector3( _x, 0, _y );
movement *= Time.deltaTime * speed;
if (movement != Vector3.zero) {
transform.position += movement;
transform.rotation = Quaternion.LookRotation(movement);
}
}
UpdateCamera();
}
Edit: Changed the title for better description of the problem
Your answer
![](https://koobas.hobune.stream/wayback/20220613101644im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move an object back/forth on a set path? 2 Answers
How to make an object without Rigidbody move at the same speed as an object with Rigidbody? 1 Answer
Crawl, Walk and Sprint movement speeds 1 Answer
Handling Animation and movement speed 0 Answers
Detecting what surface character is moving on and restrict movement outside 1 Answer