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

How to limit float variables ?

$
0
0
I want to limit my jumpPressure value within 10f, but as I multyply it by Time.deltatime*.3f, it gets higher every seconds. Code below to have a look , thanks in advance { private Rigidbody2D playerRb; public float jumpPressure = 0f; private float intialJump = 80f; void Start() { playerRb = GetComponent(); } void Update() { { if (Input.GetButton("Jump")) { { jumpPressure += Time.deltaTime * .3f; **// This is where the jumpPressure is getting too high every seconds and affecting my Addforce below//** } } else { while (jumpPressure > 0) { jumpPressure = (Time.deltaTime * -7f); } } } playerRb.AddForce(Vector2.up * intialJump * jumpPressure, ForceMode2D.Force);

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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