hi everyone~
i just wrote a simple 2D game like infinite runner,and i got a question about jumpping motion:
i made my game to run on my Android 4.1 mobile device and when i touch the screen ,i use addForce() and Animator.setBool() to make my character jump,here is my code piece:
public void Jump(){
rigidbody2D.velocity = new Vector2 (rigidbody2D.velocity.x,0f);
playerStuff.Anim.SetBool ("Grounded",false);
rigidbody2D.AddForce (new Vector2(0,playerStuff.JumpForce));
}
The Jump() function is probably executing more than once.
Your ‘if’ statement is ‘true’ for more than one update - your finger might be in contact with the screen for more than 1 single update. If you touch the screen for a quarter of a second, and your game is running at 60 FPS, that means that ‘Jump()’ gets called 60 * 0.25 = 20 times!
You should check the phase of the finger rather than the tap count -
oh,you’re right,at first i just tried TouchPhase.Moved,but it didnt work,and according to your explanation,just becase i touch and move on my screen ,it can be detected for more than once anain!
oh ~ you help me twice haha ,thanks:smile: