Broken Jump Physics
I am having trouble making the charater in the 2D game I am currently working on jump, because when I click the jump button it will move upwards extremely fast, reach the max height of it's jump, then instantly start falling downwards at the speed determined in the gravity setting. Also, the height it reaches when jumping doesn't change when the gravity is modified, as shown in this clip of me jumping with gravity turned off completely: Here is my player movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField]
float MovementSpeed = 10f;
[SerializeField]
float JumpForce = 500f;
public Rigidbody2D PlayerRB;
public Collider2D Floor;
bool Grounded = true;
private void FixedUpdate()
{
PlayerRB.velocity = new Vector2 (Input.GetAxis("Horizontal") * MovementSpeed * Time.deltaTime, 0);
if (Input.GetKey("space") == true && Grounded == true)
{
//PlayerRB.AddForce(new Vector2(0, JumpForce));
PlayerRB.velocity = new Vector2(0, JumpForce);
Grounded = false;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "Floors")
{
Grounded = true;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.name == "Floors")
{
Grounded = false;
}
}
}
(There are probably better neater ways to do this; I am not a very good programmer)
I have linear drag and angular drag turned off, and I am using the default scale. I have tried adjusting all of the options for the rigidbody component, but it makes no difference.
Is there anything I am doing wrong that is causing this? (As I said before, I am a begginer when it comes to unity.)