Question by
Bleakmountain50 · Aug 03, 2017 at 05:22 AM ·
2dmovement2d-platformerflying
2D Charaecter Flying Away
When I hold W my character flies away. is there a way to put a cap on how long you can go up for?
Here's my code: public float moveSpeed; public float jumpPower;
void Update ()
{
if (Input.GetKey(KeyCode.D))
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.A))
transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
Rigidbody2D rb = GetComponent<Rigidbody2D> ();
if (Input.GetKey(KeyCode.W))
rb.AddForce(Vector2.up * jumpPower);
}
Comment