hi i am trying to make the player jump but i dont know whats wrong ,and before someone post i increased the jump force to 9999.
the code
public float speed = 5;
public Rigidbody player;
Vector3 velo = Vector3.zero;
public int jumpforce;
bool falling = false;
// Start is called before the first frame update
void Start()
{
player.GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float xmove = Input.GetAxisRaw("Horizontal");
float zmove = Input.GetAxisRaw("Vertical");
Vector3 moveright = player.transform.right*xmove;
Vector3 moveforward = player.transform.forward*zmove;
velo = (moveright + moveforward).normalized * speed*Time.deltaTime;
player.MovePosition(player.position +velo) ;
if (Input.GetKeyDown("space")&&falling==false)
{
player.AddForce(0, jumpforce , 0,ForceMode.VelocityChange);
}
falling = true;
}
}