Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Jump problem

$
0
0
Hi, I am having trouble making a jump which allows the player to either hold the screen to jump continuously or tap the screen once and just jump once. My script below is what I am using but since GetMouseButton(0) is being called more than once while the player is on the ground the rigid body is getting the force added more than once too which means the player flies way up into the air. Is there a way which I can call the rigidbody.AddForce() just once using this method or will I need to use a different method? thanks var jump : boolean; var grounded : boolean = false; var groundCheck : Transform; var groundRadius : float = 0.2f; var whatIsGround : LayerMask; var myRigidbody : Rigidbody2D; function FixedUpdate(){ grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround); } function Update(){ if(Input.GetMouseButton(0)){ if(grounded){ jump = true; } } if(jump){ myRigidbody.AddForce(new Vector2(0, 1500f * Time.fixedDeltaTime)); jump = false; } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>