How can i add a groundCheck to my script?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playerMovement : MonoBehaviour {
public Vector2 jumpHeight;
public Vector2 fall;
public bool isGrounded = true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
GetComponent<Rigidbody2D>().AddForce(jumpHeight, ForceMode2D.Impulse);
}
}
}
Comment
Best Answer
Answer by MounirDev · Feb 20, 2020 at 12:27 PM
If you want to check the ground before jumping, you can use Raycasting https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
Your answer
Follow this Question
Related Questions
isGrounded not working,is grounded stops players from jumping 1 Answer
,Fps Controller jumps automaticalley 0 Answers
I am slowly falling down with the jump animation 4 Answers
While (starting jumping or in jump) holding W key makes game object jump high and fall slow. 1 Answer
Jump, if I touch button,Jump if I pres the touch button 0 Answers