- Home /
My player doesn't jump high enough.,My player doesn't jump exact.
I'm trying to make player jump a fixed distance but it isn't exact what I want. Here is my code:
float jumpDistance = 1.5f;
bool jump;
Rigidbody2D rgb;
// Start is called before the first frame update
void Start()
{
rgb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
}
private void FixedUpdate()
{
if (jump)
{
jump = false;
rgb.AddForce(Vector2.up * GetJumpForce(), ForceMode2D.Impulse);
}
}
float GetJumpForce()
{
return Mathf.Sqrt(2f * Physics2D.gravity.magnitude * rgb.gravityScale * jumpDistance) * rgb.mass;
}
When I jump, my player can only get 1.44 height
Comment
Answer by flare38888 · Mar 02, 2021 at 05:33 PM
The way you fix this is to NOT use rigid body, because this just adds a force. Instead use transform.translate.
Your answer
Follow this Question
Related Questions
Mobile platformer jump not working 2D 1 Answer
Hold to jump higher 0 Answers
Problem with Rigidbody.AddForce on Android 1 Answer
Jump problem 1 Answer
Problems with Jumping 0 Answers