I’ve been trying scripts of jumping and this works good for me:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
public Vector3 jump;
public float jumpForce = 2.0f;
public bool isGrounded;
Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
void OnCollisionStay()
{
isGrounded = true;
}
void Update(){
if(Input.GetKeyDown(KeyCode.Space) && isGrounded){
rb.AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
}
However, there are some issues that should be fixed:
-When the player is running and I press space, the jump is longer than it should be.
-When the player is jumping, if you press jump again, it makes another small jump. This only happens once per jump, so you can’t “fly”. How can I fix that??
Thank you.