how do i solve “isGrounded” is not defined when i write script for character control?
Show your code please
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class characercontroller : MonoBehaviour
{
CharacterController characterController;
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
characterController = GetComponent();
}
void Update()
{
if (characterController.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis(“Horizontal”), 0.0f, Input.GetAxis(“Vertical”));
moveDirection *= speed;
if (Input.GetButton(“Jump”))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
}
}
Next time you should use the code feature in forum. It’s easier to read then
It might be a problem with the order of how your code is executed. Maybe change the if statement “if(characterController.isGrounded){}” to later in the Update(). The controller might have to initiate characterController.Move() first.
public class characercontroller : MonoBehaviour
{
CharacterController characterController;
public float speed = 6.0f;
public float jumpSpeed = 8.0f;
public float gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
void Start()
{
characterController = GetComponent<CharacterController>();
}
void Update()
{
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
if (characterController.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection *= speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
moveDirection.y -= gravity * Time.deltaTime;
}
}
If something doesn’t work, you should insert
Debug.Log("Has done ^^^");
or create a public boolean that is true if the function has been processed, so you know it has passed.
You don’t say how your charactercontroller is actually grounded though, it might be sitting on a collider within your character.
Also:
Colliders randomly stops working page-2
still not working
Please make your own thread instead of reviving an old one which might have had an entirely different cause for their problem than what you are experiencing. While you are at it, there please post your code using code tags and post your actual, full error message including line numbers and everything.