- Home /
Question by
Lost_Syndicate · Jun 04, 2018 at 05:45 PM ·
c#movementvelocity
Gradually slow down motion while jumping?
I tried disabling my script section, (The movement part) but it doesn't keep in motion (Using transform.translate instead of rb.addforce (Much easier)) Is there a way to store an objects velocity, and gradually slow it down? Here are parts of my script:
if (jog)
{
Vector3 dir = new Vector3(0, 0, 0);
float z = Input.GetAxis("Vertical") * jSpeed / divideModifier;
float x = Input.GetAxis("Horizontal") * jSpeed / divideModifier;
dir.x = x;
dir.z = z;
transform.Translate(dir.x / 1.5f, 0, dir.z);
dir.Normalize();
}
// Jumping part
if (Input.GetKey(KeyCode.Space) && IsGrounded())
{
// rb.AddForce(0, jumpspeed, 0);
Vector3 jumpVel = new Vector3(0, jumpSpeed, 0);
rb.velocity = rb.velocity + jumpVel;
}
For an example, lets say im jumping, (Without moving) I don't want the value to subtract into nothing (Since im already not moving in the first place) ; Gradually decrease as your moving (When you jump) And disable the movement controls. Anyone know how i would do this?
Comment