Question by
Incmart94 · Mar 29, 2016 at 06:09 PM ·
script.rigidbody2dvelocity
How to specify a maximum height velocity for rigidbody game object
I want to specify a maximum height velocity that the rigidbody can not pass even if the control is being pressed. Below is my code, I need a way to stop the velocity even if the player is still pressing the mouse button or space key.
Rigidbody2D rb2D; void Start () { rb2D = GetComponent(); }
void FixedUpdate()
{
//Time.timeScale = 3f;
if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.Space))
{
rb2D.velocity = new Vector2(1, 1) * Time.deltaTime * speed;
}
}
Comment