Frustrated, controller grounded

So problems I beat my head against the wall to solve are now problems again. I cant jump, the controller is no longer grounded… i changed nothing. I am really thinking unity just isnt for me.

What am i missing where if the controller is grounded info, in the editor? in the code? what the hell is going on. why did this work and now it isnt?

Please show the code that you are using, using Code Tags.

Thanks for looking at it.
Sorry for my frustration.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateBase : MonoBehaviour
{
    // docs.unity3d.com/ScriptReference/CharacterController.Move.html
   
    // variable to reference the character controller
    public CharacterController controller;
   
    // vel values in xyz
    private Vector3 playerVelocity;
   
    // grounded true false
    private bool groundedPlayer;
   
    // movement speed
    private float playerSpeed;
   
    // target of jump height
    private float jumpHeight = 1.0f;
   
    // downward force
    private float gravityValue = -9.8f;
   
    // movement vectors
    private float xAxisValue = 0f;
    private float zAxisValue = 0f;
   
    // adding two methods of forward motion but keeping forward speed the same
    private float gokeys = 0f;   
    private float gomouse = 0f;
   
    // axis values for movement
    private float up = 0f;
    private float down = 0f;
    private float left = 0f;
    private float right = 0f;
       
    // left Right mouse speed
    private float mouseHorSpeed = 10f;
   
    // Start is called before the first frame update
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }
   
    // Update is called once per frame
    void Update()
    {       
        // Ground Check, reset vel to 0, if not jumping - This isnt working. velocity just keeps getting higher in value (negative number)
        groundedPlayer = controller.isGrounded;
        Debug.Log(groundedPlayer); // -----------------------------------------------
        //if (groundedPlayer && playerVelocity.y < 0f)
        if (controller.isGrounded && playerVelocity.y < 0f)
        {
            playerVelocity.y = 0f;
        }
        Debug.Log(playerVelocity); // -----------------------------------------------
       
        // Jump
        if (Input.GetKeyDown(KeyCode.Keypad0) && controller.isGrounded)
        {
            playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
            Debug.Log("Jump Condition true"); // ------------------------------------
        }
       
        // Falling back down
        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime);
           
        // Axis Values
        if (gokeys + gomouse >0f)
        {
            up = 1f;
        }
        if (gokeys + gomouse <1f)
        {
            up = 0f;
        }       
        zAxisValue = up+down;
        xAxisValue = left+right;

        // Input Keys Assigned Below
        if(Input.GetKey(KeyCode.UpArrow))
        {
            gokeys = 1f;
        }
        if(!Input.GetKey(KeyCode.UpArrow))
        {
            gokeys = 0f;
        }
        if(Input.GetKey(KeyCode.Mouse0) && Input.GetKey(KeyCode.Mouse1))
        {
            gomouse = 1f;
        }
        if(!Input.GetKey(KeyCode.Mouse0) | !Input.GetKey(KeyCode.Mouse1))
        {
            gomouse = 0f;
        }       
        if(Input.GetKey(KeyCode.DownArrow))
        {
            down = -1f;
        }
        if(!Input.GetKey(KeyCode.DownArrow))
        {
            down = 0f;
        }
        if(Input.GetKey(KeyCode.LeftArrow) && Input.GetKey(KeyCode.Mouse1))
        {
            left = -1f;
        }
        if(!Input.GetKey(KeyCode.LeftArrow) | !Input.GetKey(KeyCode.Mouse1))
        {
            left = 0f;
        }
        if(Input.GetKey(KeyCode.RightArrow) && Input.GetKey(KeyCode.Mouse1))
        {
            right = 1f;
        }
        if(!Input.GetKey(KeyCode.RightArrow) | !Input.GetKey(KeyCode.Mouse1))
        {
            right = 0f;
        }
       
        // Moved speed options here to assign move values to more conditions
        if (up !=0f)
        {
            playerSpeed = 3.0f;
        }
        if (left + right !=0f)
        {
            playerSpeed = 2.4f;
        }
        if (down !=0f)
        {
            playerSpeed = 1.4f;
        }   

        // Mouse rotate with RMB
        float h = mouseHorSpeed * Input.GetAxis("Mouse X");
       
        //if (groundedPlayer && Input.GetKey(KeyCode.Mouse1)) // Rotates with mouse and RMB only when grounded
        if (Input.GetKey(KeyCode.Mouse1)) // Rotates with mouse and RMB regardless of when grounded
        {
            transform.Rotate(0, h, 0);
        }
       
        // Rotate with keys
        if (Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.Mouse1))
        {
            transform.Rotate(0, -1, 0);
        }
        if (Input.GetKey(KeyCode.RightArrow) && !Input.GetKey(KeyCode.Mouse1))
        {
            transform.Rotate(0, 1, 0);
        }   

        // Moving
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        Vector3 vright = transform.TransformDirection(Vector3.right);
        Vector3 move = new Vector3(xAxisValue, 0, zAxisValue);
               
        controller.Move(forward * Time.deltaTime * playerSpeed * zAxisValue);
        controller.Move(vright * Time.deltaTime * playerSpeed * xAxisValue);
       
    }
}

What is your Debug.Log output? You’ll want to place many more, and add the variable values to the Debug.Log output to see what is going on

Debug.Log("Grounded value = " + groundedPlayer.ToString());

here was the result from Debug.Log("Grounded value = " + groundedPlayer.ToString());
Grounded value = False
UnityEngine.Debug:Log (object)
RotateBase:Update () (at Assets/RotateBase.cs:54)

Debug.Log(groundedPlayer); returns
False
UnityEngine.Debug:Log (object)
RotateBase:Update () (at Assets/RotateBase.cs:58)

Debug.Log(playerVelocity); returns
(0.0, -260.1, 0.0)
UnityEngine.Debug:Log (object)
RotateBase:Update () (at Assets/RotateBase.cs:64)

and Debug.Log(“Jump Condition true”); of course wont return anything until it starts working.

this object is the parent of a “head” also but I assume it has no effect. it was working and i dont know that i changed anything. I have had a busy week thus far with work but will give it some proper attention soon.

Thanks again for your help.

So what are your conclusions from the additional debug output? Did you expect grounded to be true or false?

I made a new project to add elements one at a time until failure occurs…
project has one block on a larger block.
the “player” block with the script is on top and has a character controller added.
it is set slightly high to fall to the other block upon startup. this has always seemed to work and is still working.
script is on top “player” block

block on block code with jump function - working
code with movement added - fails
Im suspicious of the “0” in the xyz “y” position in line 78…
it feels like it should be a “null” not a zero?
-edit- i relpaced the zero “0” with playerVelocity.y it seems like im trying to define movement in the y axis more than once but that didnt work the debug result is still “false” and jump function doesnt work.

These lines that were added when it breaks are noted in code and their associated variables are noted.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestingGrounded : MonoBehaviour
{
    // docs.unity3d.com/ScriptReference/CharacterController.Move.html
 
    // variable to reference the character controller
    CharacterController controller;
 
    // vel values in xyz
    private Vector3 playerVelocity;
 
    // grounded true false
    private bool groundedPlayer;
 
    // movement speed
    private float playerSpeed;
 
    // target of jump height
    private float jumpHeight = 1.0f;
 
    // downward force
    private float gravityValue = -9.8f;
 
    // ********************************************************************************
    // ********************************************************************************
    // ADDING LINES BELOW BREAKS THE INTENDED FUNCTION - NOT GROUNDED
    // Moving
    private float xAxisValue;
    private float zAxisValue;
    // ********************************************************************************
    // ********************************************************************************
    
    // Start is called before the first frame update
    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
       
    // ********************************************************************************
    // ********************************************************************************
    // ADDING LINES BELOW BREAKS THE INTENDED FUNCTION - NOT GROUNDED
        xAxisValue = Input.GetAxis("Horizontal") * playerSpeed;
        zAxisValue = Input.GetAxis("Vertical") * playerSpeed;
    // ********************************************************************************
    // ********************************************************************************
    
        // for testing -------------------------------------------------
        Debug.Log("Grounded value = " + groundedPlayer.ToString());
 
        // Ground Check, reset vel to 0, if not jumping - This isnt working. velocity just keeps getting higher in value (negative number)
        groundedPlayer = controller.isGrounded;
        Debug.Log(groundedPlayer); // -----------------------------------------------
        //if (groundedPlayer && playerVelocity.y < 0f)
        if (controller.isGrounded && playerVelocity.y < 0f)
        {
            playerVelocity.y = 0f;
        }
        Debug.Log(playerVelocity); // -----------------------------------------------
    
        // Jump
        if (Input.GetKeyDown(KeyCode.Keypad0) && controller.isGrounded)
        {
            playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
            Debug.Log("Jump Condition true"); // ------------------------------------
        }
    
        // Falling back down
        playerVelocity.y += gravityValue * Time.deltaTime;
        controller.Move(playerVelocity * Time.deltaTime);
    
        // ********************************************************************************
        // ********************************************************************************
        // ADDING LINES BELOW BREAKS THE INTENDED FUNCTION - NOT GROUNDED
        // Moving
        Vector3 forward = transform.TransformDirection(Vector3.forward);
        Vector3 vright = transform.TransformDirection(Vector3.right);
        Vector3 move = new Vector3(xAxisValue, 0, zAxisValue);
            
        controller.Move(forward * Time.deltaTime * playerSpeed * zAxisValue);
        controller.Move(vright * Time.deltaTime * playerSpeed * xAxisValue);
        // ********************************************************************************
        // ********************************************************************************
    }
}