Player Controller

I started looking at making our current character controller able to stand and move with platforms, and get pushed around. The current controller works very much like the HL1/2 controller, in that it traces a box around the world and has no "real" physical presence.

So I got about 30 minutes into this and realised I was basically emulating a physics engine and it was a huge hack. It would be better if we could be physics with a character controller hacked in, rather than a character controller with physics hacked in.
The rigidbody for the player controller is a bit of a weird shape. It's a box at the bottom and a capsule at the top.
The box is used for the feet. It has high friction. Using a box here instead of a capsule makes it feel like the hl2 player controllers. You don't sink when walking near an edge etc.

The body is wider than the feet, and has no friction. This means that when you graze a wall it doesn't slow you down. This is important when jumping against walls, you don't want the wall to grab you and be unable to jump.
Because the player has weight, they can push things, and those things react as they should.
It's just a physics object so it can sit on a platform and move along with it like any other. We do some calculations under the hood to give you eye rotation and ground velocity.

The controller pays attention to the ground friction, so things like ice are possible.

Full ducking support is built in. It won't unduck until it has room to.
It also fully supports duck jumping too. When it duck jumps it moves the body upwards so the eye position stays in the same place, and allows you to get to higher places than just regular jumping.


The controller can have different move modes. It can be extended with your own move-modes easily. We include a ladder movement, which detects a ladder trigger. (we're working on climb animations)


We also included a swimming move mode by default, which is enabled by being inside a water trigger. The player does a little jump when leaving the water to help them get to the edge.

I loved the crushing stuff in Half-Life. Scientists being gibbed by a door was awesome. So I want the same thing to be possible in s&box. I've done a bunch of work towards this, but still want something more generic, so it's built into the physics engine.

You can get pushed by other physics objects, and react how you would expect.

Stepping up and down is an important part of any character controller

There's a built in camera controller. It's a first person and third person camera. The third person traces backwards to avoid clipping through walls.
You can turn this feature off by right clicking the camera tab, and create your own camera controller in another component.
The built in animator will take care of rotating and setting animgraph variables on the player model. It can also play footstep sounds automatically.
You can also turn this off and code your own animator in another component.
The built in input feature sets the player's wish velocity, duck wish state and jump. It also has pressing built in, allowing the player to automatically interact with any component that implements the IPressable interface (like buttons, doors etc).
You can also turn this off and code your own input system in another component.
I like this implementation. I have been weary in the past of doing too much, providing functionality that developers should be implementing themselves. But I think this is the right thing. It's got an easy mode, for the 90%.. where you don't have to do anything and it's good enough. Then it's got a hard mode for the 10% that know what they're doing and want more.

It has turned making a player controller with all these features from "download this library, create this, do this, press this, write this" - to just two clicks.

trophy 720
Apr 2021 138 posts
trophy 775
Jan 2024 35 posts
that's pretty useful
trophy 190
Oct 2023 11 posts
pretty good
trophy 275
Apr 2021 14 posts
Amazing!
trophy 0
Jul 2024 3 posts
Could a cylinder be a viable solution instead of capsule + box? It would make head jumping other players easier which could be fun
trophy 175
Jul 2023 3 posts
Nice stuff!
trophy 720
Apr 2021 138 posts
Yeah a cylinder would be nice, but have to be careful not to add a "lip" or the player will get caught up on edges when falling
trophy 95
Feb 2024 10 posts
i tried it today and i can say that it is the best player controller out of the box
trophy 50
Aug 2023 3 posts
Woah!
trophy 245
Mar 2023 15 posts
Very cool
trophy 0
Nov 2024 3 posts
will you get sent flying if youre going fast while noclipping and stop noclipping (like in gmod)
trophy 0
Apr 2023 3 posts
This is Amazing.
trophy 60
Aug 2022 7 posts
real
trophy 50
Nov 2024 3 posts
good stuff :)
trophy 0
Jul 2023 3 posts
Great job Garry, but there’s an issue that needs improvement in my opinion. When pressing ‘crouch’, the camera makes a very abrupt height change.
trophy 415
Sep 2022 3 posts
Thank you Gary very cool, im definitely in the percentage of people who prefer to not spend a bunch of time coding a player model, especially when things are constantly changing in an alpha causing code to break
trophy 5
May 2021 3 posts
this is game changing for simplifying the development process of source style games
trophy 0
Nov 2023 3 posts
please add more graphics setting, like ao(if it use), shadow map quality, textures quality (if is possible to change) and a level of detail
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.