Gravity slow descent after jump
Basically my character jumps to the correct height, then slowly floats down until/unless I move them, then gravity resumes normally. I can't jump straight up and down without slow descent.
Tried AddForce and velocity. Both work for the jump, but both slow the descent unless I move.
public void LeaveGround()
{
// Add physics to the jump
RB.AddForce(transform.up * JumpHeight * 2f, ForceMode.Impulse);
}
First some basic questions. $$anonymous$$aybe there is already the error or we can rule it out and conclude on more complex mistakes/errors.
Is there just this one line of code where you apply force to the object or change the velocity, or does your code contain any other behavioral elements?
Have any changes been made in your Physics or Physics2D settings or are there any settings that you find strange? If so, then maybe add to the question (as a screen).
(very unlikely) It may come to a bug because you are working with the local coordinate system and not with for example Vector3.Up.
@$$anonymous$$askorian Thanks for the response. I do have one other section where movement is applied based upon the input. // read inputs float h = CrossPlatformInput$$anonymous$$anager.GetAxis("Horizontal"); float v = CrossPlatformInput$$anonymous$$anager.GetAxis("Vertical"); bool crouch = Input.Get$$anonymous$$ey($$anonymous$$eyCode.C);
// Update animation
// update the animator parameters
m_Animator.SetFloat("Forward", (v * RunSpeed) + (h * TurnSpeed), 0.1f, Time.deltaTime);
m_Animator.SetFloat("Turn", h, 0.1f, Time.deltaTime);
m_Animator.SetBool("OnGround", true); // m_IsGrounded
m_Animator.SetFloat("Jump", RB.velocity.y);
// $$anonymous$$ove the character
transform.Rotate(0, h * TurnSpeed, 0);
RB.AddForce(transform.forward * v * RunSpeed, Force$$anonymous$$ode.Impulse);
Incidentally, I'm able to watch the Velocity.y value, and it goes positive on the way up, negative during correct speed fall, but then hits zero and the descent slows.
No other changes to Physics in the code or editor.
When it's falling slow, if I move or rotate, then gravity resumes normally. I took out the on_ground checks so that I could do that, rather than waiting a $$anonymous$$ute for touchdown.
Okay next, just to imagine: how exactly does the jump go? I'm just trying to reproduce the mistake. When I use your LeaveGround method, the jump works normally.
So how exactly does he work for you? You mean your object jumps normally but falls too slowly. If this already occurs at the highest point, so jump up to JumpHeight -> velocity.y approaches 0 -> At the highest point velocity.y = 0. Does the error occur from there on? Is the fall speed just lower than it should be or is it something more special. You mean the value is negative when falling down, as it should be, until it reaches 0. At which point in time or at which point velocity.y reaches a value of 0 as well as at the highest point.
So there's a animation burned into the jump. To that, I add extra force to get him higher. He goes all the way up, as expected, then comes down a little bit at normal speed, most likely from the animation, then it slows down to a floating descent. It remains that slow, unless I move forward or rotate, so it almost looks like it's standing on a platform and then falls off when you move forward, except that it is still falling, just more slowly.
Stepping out. Will be back this evening. Thanks for taking the time.
Just an idea.
Could I be that there is a root motion applied to the jump Animation, which is moving up your object also when is falls down. To check if so, just uncheck "Apply Root motion" in the animator inspector.
Here a tutorial for root motion:
Also, is the Animation in place? So if you look at your Animation file in the inspector, is the object moving away from it's start Position (Animation preview window). The Problem could be that there is a root moving Vector applied to the Animation, which moves the object upwards. If thats the case this should explain why the object falls down normally after you move and rotate because then another animation is active and no upward movement occurs
@$$anonymous$$askorian Here's what it looks like. https://www.ctacinvestigations.com/gravity.avi
The Forward value is vertical input * Speed. The Jump value is the Rigidbody.velocity.y.
Your answer
Follow this Question
Related Questions
Why my gravity direction is rotating with transform.rotation? 1 Answer
Rigidbody doesn't seem to apply gravity 1 Answer
Adding Gravity to a game object to make a black hole sucking effect. 1 Answer
Space,Gravity,RigidBody,Physics Forces 0 Answers
Order of execution: AddForce, rigidbody movement, velocity update? 0 Answers