- Home /
Question by
unity_1vanessanc2 · Oct 12, 2021 at 08:52 PM ·
ground detection
i am new to unity and c#, i made a something but can anyone help me code a simple groundcheck that makes jump true when on the ground while cant jump while its on the air
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerMovement : MonoBehaviour { private bool Jump = false; public float MoveSpeed = 7f;
// Update is called once per frame
void Update()
{
Jump = Input.GetKey(KeyCode.UpArrow);
}
private void FixedUpdate()
{
//Make the character move left and right
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += new Vector3(MoveSpeed, 0f, 0f) * Time.deltaTime;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += new Vector3(-MoveSpeed, 0f, 0f) * Time.deltaTime;
}
if (Jump)
{
GetComponent<Rigidbody2D>().velocity = new Vector3(0f, 12f, 0f);
}
}
}
Comment
Your answer

Follow this Question
Related Questions
Why is my character not on the ground? 1 Answer
Player can jump on non ground hazards? 1 Answer
Character Getting Caught on Colliders & Jump Animation Cancelled by Ground Check 0 Answers
Custom Controller 1 Answer
ground detection fails 0 Answers