Search Unity

Character Controller Falls Through Colliders

Discussion in 'Physics' started by GerPronouncedGrr, Dec 26, 2019.

  1. GerPronouncedGrr

    GerPronouncedGrr

    Joined:
    Mar 30, 2013
    Posts:
    25
    I have a model (a Mixamo Fuse character, with animations), which has on it a Character Controller, a script, and which is a child of an empty game object. It does not have on it a Rigidbody of any kind. All my collision layers are set to collide with each other. My character is positioned 1 unit above a plane which has on it a mesh collider. And yet, when I press play, the character falls until half its body is embedded into the plane, then stops. I can move around normally, but remain inside the plane. Below is the script for reference. Unity version is 2019.3.0b12

    Code (CSharp):
    1. using System;
    2. using Rewired;
    3. using UnityEngine;
    4.  
    5. public class Character : MonoBehaviour
    6. {
    7.     public int playerID = 0;
    8.     public float moveSpeed = 5.0f;
    9.     public float jumpSpeed = 8.0f;
    10.     public float gravity = 20.0f;
    11.  
    12.     private Player _player;
    13.     private CharacterController _cc;
    14.     private Vector3 _moveVector = Vector3.zero;
    15.     private bool _jump;
    16.  
    17.     private void Awake()
    18.     {
    19.         _player = ReInput.players.GetPlayer(playerID);
    20.         _cc = GetComponent<CharacterController>();
    21.     }
    22.  
    23.     private void Update()
    24.     {
    25.         GetInput();
    26.         ProcessInput();
    27.     }
    28.  
    29.     private void GetInput()
    30.     {
    31.         _moveVector.x = _player.GetAxis(0);
    32.         _jump = _player.GetButtonDown(1);
    33.     }
    34.    
    35.     private void ProcessInput()
    36.     {
    37.         if (_cc.isGrounded)
    38.         {
    39.             _moveVector = new Vector3(_moveVector.x, 0.0f, 0.0f);
    40.             _moveVector *= moveSpeed * Time.fixedDeltaTime;
    41.  
    42.             if (_jump)
    43.             {
    44.                 _moveVector.y = jumpSpeed;
    45.             }
    46.         }
    47.  
    48.         _moveVector.y -= gravity * Time.fixedDeltaTime;
    49.  
    50.         _cc.Move(_moveVector * Time.fixedDeltaTime);
    51.     }
    52. }
    53.  
     
  2. GerPronouncedGrr

    GerPronouncedGrr

    Joined:
    Mar 30, 2013
    Posts:
    25
    Update

    I added a few animations and an animation controller, wrote a few extra lines of code to control a couple animator parameters, and now the character floats slightly above the ground instead of getting embedded in it. The collider has not changed at all. If I view it while the game is running, it very clearly is not touching the ground.