Hi, I have written a function in my player controller to make the character jump, however I seem to get pretty random results like every 3rd or 4th jump seems to be higher or sometimes it barely jumps at all.
Have I made an error in assuming that rigidbody.addforce was the way to go here?
My player is a 2d plane that has a rigidbody with gravity.
I have variables assigned on the player to control this
var playerOneJumpRate = 1.0; //Players time between jumps
var playerOneJumpPower = 600; //Players Jump Power
var playerOneControlJump= ","; //Player Controls (re-mappable)
I also have the following control function on the player
// This function controls the players jump - makes the player wait to be able to jump again
function jumpTime()
{
while (true)
{
if (Input.GetKeyDown (GameObject.Find("GameObjectPlayerOne").GetComponent(ScriptPlayerOneStats).playerOneControlJump)) {
rigidbody.AddForce (Vector3.up * GameObject.Find("GameObjectPlayerOne").GetComponent(ScriptPlayerOneStats).playerOneJumpPower);
yield WaitForSeconds(playerOneStats.playerOneJumpRate);
}
else
{
yield;
}
}
}
↧