Hello everybody,
I’m using iTween to define the main character’s movement functions in a 2D game. For jumping I’m using a quite simple approach, using just iTween.MoveAdd instead of a more complex physics-based approach.
The character is moved 5 units upwards while the fire button is pressed, and sent back to his original position when the button is released.
It works good enough if such button is kept pressed for at least 200-300 ms, otherwise if the player presses repeatedly or too fast, the script misses some events, resulting in multiple jumps or the GetButtonUp event not doing much.
It seems that such time interval comes from a new iTween object being instanced and then deleted from the character gameobject, but I’m not too knowledgeable about unity to make such assumption.
Any help, suggestion, or example is welcome. ( I’ve already bought some examples from the iTween store, and they’re quite useful to learn how iTween behaves. is there any of them that address such problem? )
By the way, here’s a snippet from my code:
public class MainCharacterScript : MonoBehaviour {
public bool isJumping = false;
public bool isLanding = true;
// Use this for initialization
void Start () {
}
void topUp() {
isJumping = true;
isLanding = false;
}
void topDown() {
isJumping = false;
isLanding = true;
}
void fakeJumpDownState() {
iTween.MoveAdd(gameObject,iTween.Hash("y",5,"speed",30,"easetype","easeInOutElastic","onstart","topUp"));
}
void fakeJumpUpState() {
iTween.MoveAdd(gameObject,iTween.Hash("y",-5,"speed",30,"easetype","linear","onstart","topDown"));
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown("Fire1") (isLanding == true)) {
fakeJumpDownState();
print("Jumping");
}
if(Input.GetButtonUp("Fire1") (isJumping == true)) {
fakeJumpUpState();
print("Landing");
}
}
}