Hey! So im working on a project for my game design class , i have a first person character that gets chased around by a monster, i just finished making the monster AI today and got it to reference the fpc movements, however once i did that, my fpc was no longer able to move, in the process of troubleshooting that, they now fall through the floor ![]()
`public class FPSController : MonoBehaviour
{
public Camera playerCamera;
public float walkSpeed = 8f;
public float runSpeed = 15f;
public float jumpPower = 7f;
public float gravity = 90f;
public float lookSpeed = 2f;
public float lookXLimit = 45f;
public bool isRunning = true;
public Transform groundCheck;
public float groundDistance = 5f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
private CharacterController characterController;
private float rotationX = 0f;
void Start()
{
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
float inputHorizontal = Input.GetAxis("Horizontal");
float inputVertical = Input.GetAxis("Vertical");
bool isRunning = Input.GetKey(KeyCode.LeftShift);
bool isJumping = Input.GetButton("Jump");
Debug.Log(characterController.isGrounded);
Move(inputHorizontal, inputVertical, isRunning, isJumping);
if (CanMove())
{
rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
}
{
// Example logic to determine if the player is running
if (Input.GetKey(KeyCode.LeftShift))
{
isRunning = true;
}
else
{
isRunning = false;
}
}
void Move(float inputHorizontal, float inputVertical, bool isRunning, bool isJumping)
{
if (characterController.isGrounded)
{
// Calculate movement direction based on input
Vector3 forward = transform.forward * inputVertical;
Vector3 right = transform.right * inputHorizontal;
Vector3 movement = (forward + right).normalized;
// Calculate movement speed
float speed = isRunning ? runSpeed : walkSpeed;
// Apply movement speed and direction
Vector3 moveDirection = movement * speed;
// Handle jumping
if (isJumping)
{
moveDirection.y = jumpPower;
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the character controller
characterController.Move(moveDirection * Time.deltaTime);
}
}
bool CanMove()
{
// Define conditions under which movement is allowed
// For example, you can add logic here to disable movement under certain circumstances
return true;
}
}
}`
i did show my project to my professor and he figured out that the issue is (partially) that is.grounded is stuck on false. but as for falling through the world, were clueless. can anyone help?