I want it to jump SMOOTHLY but it just teleports the object high up.
This is my script -
public Rigidbody rb;
public Camera cam;
public bool isGrounded = false;
[Header ("Movement")]
public float speed = 5f;
public float jumpForce = 1f;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float horizontalSpeed = Input.GetAxis ("Horizontal");
float verticalSpeed = Input.GetAxis ("Vertical");
Vector3 Movement = new Vector3 (horizontalSpeed, 0f, verticalSpeed);
Movement = Camera.main.transform.rotation * Movement;
rb.velocity = Movement * speed;
if (jumpForce <= 15f && Input.GetKey(KeyCode.Space))
{
jumpForce ++;
}
if (Input.GetKeyUp(KeyCode.Space) && isGrounded == true)
{
rb.AddForce(new Vector3(0f, jumpForce, 0f), ForceMode.Impulse);
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.transform.position.y <= transform.position.y)
{
isGrounded = true;
jumpForce = 1f;
}
}
void OnCollisionExit(Collision other)
{
isGrounded = false;
}
}