Hi guys, my intention was to create a character (a bird) that flies; so I added a Jump control script, a constant force that pulls him down, and I’ve set him as rigidbody (for collisions with objects). So I should press Jump button to balance the bird in the air (when he goes too high or on the groud he dies).
The code works but: when I press the jump button more than 2 times, he flies too high and the constant force isn’t high enough to push him down or ,if I set constant force higher, he falls faster down.
Here is the code for the Jump Button:
public class Jump : MonoBehaviour {
bool JumpPressed=false;
public float jumpAccelleration=3;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!JumpPressed)
JumpPressed = Input.GetKeyDown (KeyCode.Space);
}
void FixedUpdate(){
if (JumpPressed) rigidbody.AddForce (new Vector3 (0, jumpAccelleration,0), ForceMode.Impulse);
if (JumpPressed) JumpPressed = false;
}
}
Can someone improve my code or give me some tips to control better my character??
PS. Sorry for bad english, I’m italian