Hi Guys
I m having trouble setting my groundCheck flag to false the change state is there but my character is still able to jump to infinity.
I have assigned groundCheck to my ground prefab. which is on my ground layer. i have also assigned the mask to the ground layer. what am i missing?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour {
bool isGrounded = false;
public float force;
public float maxSpeed;
public Vector2 jumpHeight;
public Transform groundCheck;
public LayerMask groundLayer;
private Rigidbody2D rb2d;
void Start () {
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void LateUpdate () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = 0;
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.001f, groundLayer);
if (rb2d.velocity.magnitude < maxSpeed) {
Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
rb2d.AddForce (movement * force);
}
if (Input.GetKeyDown (KeyCode.Space) && isGrounded) {
isGrounded = false;
rb2d.AddForce (jumpHeight, ForceMode2D.Impulse);
}
}
}