- Home /
Another Jump Question
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);
}
}
}
Answer by ScaryFace · Feb 10, 2018 at 11:56 PM
Ok so i used an Ontrigger Event method to change the state of IsGrounded works fine, but id still like to use the Overlap Circle solution.
Your answer
Follow this Question
Related Questions
Why is my circle cast not going the full distance? 0 Answers
Object jumps out, when stuck between two colliders. 0 Answers
Is there a way to lock velocity? 3 Answers
My player is unexplainably destroyed when collides with a collider 0 Answers
How to make stack of objects to move where bottom moves earlier than the top and stack looks natural 0 Answers