I am trying to detect when an object is grounded.
My script right now is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playermovement : MonoBehaviour
{
public CharacterController2D controller;
public Rigidbody2D rb;
float horizontalMove = 0f;
public float runSpeed = 40f;
Vector2 forceapplied;
public bool isGrounded;
public float NumberJumps = 0f;
public float MaxJumps = 2;
public float jumpHeight = 7f;
public CircleCollider2D bc;
void Start()
{
forceapplied = new Vector2(0.0f, 30f);
}
void Update()
{
if(bc.gameObject.name == "Grid") {
isGrounded = true;
NumberJumps = 0;
}
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (NumberJumps > MaxJumps - 1)
{
isGrounded = false;
}
}
private void FixedUpdate()
{
if (isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector2.up * jumpHeight);
NumberJumps += 1;
}
}
controller.Move(horizontalMove * Time.fixedDeltaTime, false, false);
}
}
In the inspector it always says that Isgrounded is false.
Can someone please help?
bc
object? \$\endgroup\$