Creating an fps Controller that doesn't suck

I rewrote my entire fpsController script today for the 4th time and I still can’t get the results I want.

My game requires a quit complex fpsController script. Here are the most important points:

  • Player slides down slopes.
  • Can’t walk along slopes
  • Movement of the ground affects the player (Moving Platforms)
  • Player should stop walking immediately then there is no input.

My biggest problem is the velocity generated by the Rigidbody.
I can set the velocity on every FixedUpdate to 0 before adding the movement force.
That gives me an absolute responsive controller but messes up Jumping and Falling behavior.

There isn’t like a single thing I need to solve. It’s the combination of them all that makes me struggle.

Can you recommand me something I can watch or read to get better understanding about bilding an solid fpsController?

Or maybe a good script (not like the standard assets) that I can take a closer look at to see how it’s done?

I thought I listed exactly what I’m trying to solve or what else would you need to know?

If you’re not afraid of code I’d recommend taking a look at the standard FPSController and RigidbodyFPSController. You can find both in Import Package->Characters. From there you can take a look at the infinite amount of their modifications on the internet.

The points you mention are usually not a problem with most controllers, and can be solved farily easily except for the moving platforms, which are an aeon-long battle, but solvable nontheless.

It is pretty difficult to suggest anything because you don’t state what the game is, or give any reference for us.
Are you looking for a classic Quake 3 controller?
Is jumping and air control of large importance, or is it going to be mostly rudimentary?
Are moving platforms limited to something like elevators(which can be cheated), do platforms ever rotate?

Also I’m just going to put this here, since it helped me improve my own controller:
https://quitbutton.wordpress.com/2017/06/06/state-driven-character-controller/

I already took a very deep look at the Standard asset FPSController and RigidController. But they booth have exaclty the same problems I run Into.

My game is a bit Portal like and Jumping and aircontroll is very important.

there are elevators and platforms but I already wrote a function that is transfering the movements.
Thats not the problem.

Thanks for the link I will take a closer look at that.

I outlined some basics here.

2 Likes

Thanks a lot. Your post is very helpful.
I used Rigidbody.addForce in combination with setVelocity. But that was leading to a lot of problems.

Your post helped me to build the Controller I wanted.

There is just one thing that I need to fix.

Currently the Friction is controlling how sharp a slope can be till the player starts sliding down.
That does work how I want it to work.

But when I’m standing infront of a wall and try to jump the jumping height is a lot less then it should be. (because of the friction between player and wall)
I can reduce the Friction to 0 to solve that but that means I need to find a different solution for the slopes.

My approche would be to set the Friction to 0 while jumping and returning it to 1 then the Player is grounded.

Is there any other way I can solve that?

In my experience the character always needs to have either zero or really small friction, because otherwise the controller will stick to every wall it touches.

There are 3 options for slopes and rigidbodies:

  • Give your slope a different physics material with really high friction and friction combine max mode. Here is a priority table that shows that even if you set your controller to zero friction, the other material can take priority.
  • You can apply countering gravity velocity to the body if it is on a slope. You’ve mentioned that you’re familiar with standard RB controller, it has a function that gets the ground slope modifier.
  • Fast, lazy, and probably bad way out: raise the collider slightly, and add another small, narrow collider where your body contacts ground with proper friction. The wide body collider will have no friction while the base collider will cling to surfaces.

I used the friction now as Multipliere. 1 while grounded and 0 while jumping.

To get the Sliding working I used the Angle of the ground to scale down the movement speed then it’s larger then 45°

It’s far from perfect and I had to deactivate the collision between the player and all small objects to make it work.

At least I have now something that gets the job done till I have a better way of controlling the player.