I have a player with Character Controller and a Player Movement Script (See Image).
My groundcheck is attached under Player which is the parent and is at the bottom of the player body. With no component.
When my player goes on terrain, 90% of my map, the player wont jump, pretty sure the ground check doesnt think its the ground. But as soon as i go to flat land it seems to work like wooden, concerte and etc.
Here is my Player movement script file and the same thing but copied pasted here, and the values if needed for the variables if changed are in image 1 at the top.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
Debug.Log("Is grounded?");
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
Debug.Log("Jump");
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
PlayerMovement.cs (1.3 KB)

