first person controller system


this is a first person controller system
it uses several capsule vs triangle queries to achieve a smooth and finished character feel

now we will begin decomposition of the system into its sub components
the operations in the update loop of the first person controller can be re ordered and customized as youd like

the only rule to this system is that you simply cannot add any velocity to the character after the velocity clip against the scene has happened

otherwise you will still continue to drift into objects that should be offering resistance to your movement

the operations of the character controller should otherwise continue to work correctly independently of the order that these operations are done in

each function runs independently

the system is extremely stable and difficult to break

velocity += hit_normals[i] * -dot_normal_velocity;

this one line is responsible for ensuring that the character clips against walls and prevents you from passing through them

this system perfectly corrects illegal velocities directly, achieving velocity clipping without introducting sticky behaviour

this naturally scales the correction so that the velocity is perfectly projected onto the surface plane of the triangle overlapped by the capsule

the system permits objects to collide for 1 frame, but prevents further collision via strict velocity clipping

no direct positional correction is ever used in this system

in this system, gravity damping behaviour is a key component of visual stability

gravity damping slightly before conventional leg forces are applied ensures a smooth landing experience visually for the player

when pressing WASD, youre describing your desired velocity in terms of the speed of the character you are playing

the direction is in localspace chosen by your WASD input

W forward, A left, S back, D right

transform.TransformDirection(desired_velocity) translates the desired velocity from WASD space to the space of the person doing the moving

W forward becomes the direction of wherever the person is physically facing

forward in WASD space is then converted to forward in local human space

after transformation from WASD space to human space, the direction will still only have a length of 1 (normalized)

it will need to be multiplied by the desired move speed of the human

extremely simple and straightforward acceleration and braking logic

can easily be replaced or extended for your specific needs

stances are formatted to be extremely easy to understand

addition of custom movement logic is made to be as easy as possible

this is an extremely lightweight and transparent system

includes easy to understand utilities and examples for parsing geometry from the unity rendering and graphics system

used to mirror and query geometry in order to interact with it