Quantcast
Channel: Latest Questions by RoboticSarcasm
Viewing all articles
Browse latest Browse all 40

How to only jump when grounded

$
0
0
So i have this basic 2D player code that can jump and move horizontally but the jump can always be initiated, even when already in air. How do i fix this? Code here: using UnityEngine; using System.Collections; public class Player : MonoBehaviour{ public float moveSpeed = 10f; public float jumpSpeed = 10f; void Update () { float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed; if (Input.GetButtonDown ("Jump")){ rigidbody2D.velocity = new Vector3(0, jumpSpeed, 0); } transform.Translate (new Vector3 (h, 0)); } }

Viewing all articles
Browse latest Browse all 40

Latest Images

Trending Articles



Latest Images

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