- Home /
Strange slow jump.
I have a rolling ball game and have this issue for so long and still don't know how to solve this. My jumping works but slowed to half when jumping on a flat. This is my jump code.
rb.AddForce(Vector3.up*jumpHeight,ForceMode.VelocityChange);
My movement
rb.AddForce(movement * currentSpeed * Time.deltaTime);
// limiting movement speed
if (rb.velocity.magnitude > maxSpeed)
{
rb.velocity = rb.velocity.normalized * maxSpeed;
}
Even when I don't include the limit it still doesn't solve it. Here's an image. I put a mark so you can tell. link image
Someone help me solve this, I really appreciate it. Thanks in advance.
Comment
Answer by LTonon · Jan 24, 2018 at 02:11 PM
As far as I can guess, maybe you could change something by applying the limit separately instead of by the vector's magnitude. Something like:
if (rb.velocity.x > maxHorizontalSpeed)
{
rb.velocity = rb.velocity.normalized * new Vector3(maxHorizontalSpeed, rb.velocity.y, rb.velocity.z);
}
if (rb.velocity.y > maxVerticalSpeed)
{
rb.velocity = rb.velocity.normalized * new Vector3(rb.velocity.x, maxVerticalSpeed, rb.velocity.z);
}
Besides, since your maxSpeed is a float I believe it's wrong to assign it the way you're doing unless you want the velocity to be the same on the x and y axis.
Your answer