- Home /
Itween gradual jump 2d
Hello everyone. I'm trying to make my player jump gradually while the button is pressed, but without success. Could someone give some idea of how to do? ITween use to make the player move through a path. The player has a rigidbody2d with isKinematic enabled and a gameobject child who has a renderer sprite
if (!jumping && Input.GetMouseButton(0)) {
StartCoroutine (Jump());
}
IEnumerator Jump (){
jumping = true;
float timer = 0.0f;
while (timer <= jumpTime) {
float height = Mathf.Sin(timer / jumpTime * Mathf.PI) * jumpHeight;
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y+height, 0);
timer += Time.deltaTime;
yield return null;
}
jumping = false;
}
Answer by awplays49 · Feb 12, 2015 at 11:23 AM
In the editor, go to
Edit > Project settings > Physics and change Y Gravity to something in the negatives, the lower the number the greater the gravity.
Next, all you need is a code like this:
if (Input.GetKey (YourJumpKey))
{
rigidbody.velocity = new Vector3 (0, JumpForce, 0);
}
Thanks for the help but it didn't work. The player does not jumped.
Your answer
Follow this Question
Related Questions
iTween gradual jump 2D 0 Answers
Gradual Jump 2d 2 Answers
2D C# destroy a GameObject on collision 2 Answers
[iTween] How to get the GameObject to look at the nodes without orientToPath 0 Answers
Character doesn't jump repeatedly 1 Answer