- Home /
Another Slow Fall Problem...
I'm trying to make a platformer for my first project, and I have the moving around working. But jumping is proving a problem. I am using a function to make the player jump:
void Jump() { rigidbody.AddForce(Vector3.up * jumpSpeed); }
but the upward momentum seems isolated to the individual frames where the jump key is pressed, meaning a very unreliable/unrealistic jump arc. Also the model just hangs in the air and falls very, very slowly.
The model is 4 units tall, has a rigidbody with drag and angular drag set to 0, and mass set to 1. Gravity is set to -9.81. I've tried playing with the mass, to no avail, and it seems like changing gravity is the wrong approach.
I can't figure out what is slowing the models decent, and the other answers I've looked at on this site either don't apply to my situation, or don't have answers yet. Can you help me?
Answer by haim96 · Aug 04, 2015 at 07:26 AM
here some advice for jumping with physics:
when you jump make sure you can't press jump again (double jump).you can do that with bool that set to true when press jump and false when get back on the ground. then check for it state when press jump. this way you will avoid apply multiple "addforce" in long jump press. it will make the jump more consistent.
you can set the gravity multiple on your player's rigidbody. this will make him fall faster. it will effect your player only and not the whole project.
you may want to try to apply the force as impulse for the jump. (forceMode.impulse) http://docs.unity3d.com/ScriptReference/ForceMode.Impulse.html
changing the mass of the rigidbody isn't changing anything at all, it still falls at the same rate. I've experimented with the code I was using. I've deleted my old script and started a new one, here it is in its entirety: using UnityEngine; using System.Collections;
public class PlayerController : $$anonymous$$onoBehaviour {
public float moveSpeed;
Rigidbody rb;
void Start () {
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate ()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (h * moveSpeed, 0f, 0f);
rb.velocity = movement;
if (v == 1)
{
}
}
}
with appologies moderators. I started the character above a plane, to see how it falls. It still falls very slowly, but when I //comment out all references to the rigidbody from the declaration of the variable (rb) to the assignement, it falls normally.
This suggests that calling the rigidbody in the script in any way interferes with its physics...
Answer by 4ntihero · Aug 04, 2015 at 10:56 PM
I see the problem now, I apologize for not seeing it early, and thanks for the help.
When I was trying to set the horizontal velocity I was also setting the vertical velocity to 0. I have replaced the Y parameter of "movement" with the object's rigidbody.velocity.y. It seems to be falling normally now.
Your answer
Follow this Question
Related Questions
Jumping only once (2D) 2 Answers
I have a problem with my jump script 1 Answer
change multiple jump to single jump 1 Answer
Can't get platforming character to jump 2 Answers
jump and check ground problem! 2 Answers