Search Unity

Character Controller source code?

Discussion in 'Scripting' started by Bonfi_96, May 19, 2018.

  1. Bonfi_96

    Bonfi_96

    Joined:
    Oct 2, 2013
    Posts:
    35
    Hi, I've written my own character controller with collision resolutions and everything and, well, it works, but I would love to see how the guys behind the engine handled it themselves.
    Also it would be a great place to start to learn and to start form for our own implementations.
    It took me forever to wrap my head around collision resolution, frame indipendent sweeping and some insane phasing.
    It's not in the source code in github but I guess it's implemented in c# too?
    Thanks!

    Edit: seems like it's implemented in c++ under the hood, found this piece of code

    Code (CSharp):
    1.     [NativeHeader("Runtime/Dynamics/CharacterController.h")]
    2.     public class CharacterController : Collider
    3.     {
    4.         extern public bool SimpleMove(Vector3 speed);
    5.         extern public CollisionFlags Move(Vector3 motion);
    6.         extern public Vector3 velocity { get; }
    7.         extern public bool isGrounded {[NativeName("IsGrounded")] get; }
    8.         extern public CollisionFlags collisionFlags { get; }
    9.         extern public float radius { get; set; }
    10.         extern public float height { get; set; }
    11.         extern public Vector3 center { get; set; }
    12.         extern public float slopeLimit { get; set; }
    13.         extern public float stepOffset { get; set; }
    14.         extern public float skinWidth { get; set; }
    15.         extern public float minMoveDistance { get; set; }
    16.         extern public bool detectCollisions { get; set; }
    17.         extern public bool enableOverlapRecovery { get; set; }
    18. }
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,336
    The CharacterController is, afaik, a wrapper for the CharacterController from PhysX, the physics engine. It's possible to get access to PhysX' source, see here.
     
    Bonfi_96 likes this.
  3. s7887177

    s7887177

    Joined:
    Dec 21, 2019
    Posts:
    5