Quantcast
Viewing all articles
Browse latest Browse all 49

2D Charge Jump Complications

I have been having trouble getting a charge jump to work. I am a beginner in java script and any help would be helpful. The script doesn't cause any errors but does not cause "jump" when the space key is released. #pragma strict public var jumpUpVel : float = 10f; public var jumpForwardVel : float = 10f; var Gravity : float = 10f; var chargeLevel : float = 0; //Don't change this in the inspector. var chargeSpeed : float = 1; //Default, the charge will go up 1 per second var isCharging = false; function Update () { if (Input.GetKey(KeyCode.Space)) { //Did the user click? if(!isCharging) { //Some what unnecessary due to the way the Input is // setup isCharging = true; CalculateCharge(); } } } function CalculateCharge () { while(Input.GetKey(KeyCode.Space)) { //Add to the charge as long as the // user is holding the button chargeLevel += Time.deltaTime * chargeSpeed; } if (Input.GetKeyUp(KeyCode.Space)){ this.gameObject.rigidbody.AddForce(jumpUpVel, jumpForwardVel, 0); //transform.position.x++; } // launch player // Reset the vars. chargeLevel = 0.0; isCharging = false; }

Viewing all articles
Browse latest Browse all 49

Trending Articles



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