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?
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?
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.
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.