Alternative to character controller and rigidbody players?

Hey everyone,

For a few weeks now I have been experimenting with various methods of handling the player movement in my FPS. Now before I go further, I need to explain what the issue is with the two standard methods people usually use are.

My game involves the changing of gravity orientation and the changing of the player’s rotation to keep them relative. this instantly rules out the character controller, as it can’t be rotated.

By adapting a rigidbody controller I found on the wiki, I was able to get the grarity thing working. However I’ve since found some huge problems with this method. When jumping by a wall the friction affects jump height and when jumping into a wall it is possible to prevent falling by sticking to it using the force applied when moving. Messing with physics materials isn’t an option as these walls may be foors to other rigid bodies that have different gravity directions.

What are my options? Lots of people use rigidbody characters yet I have struggled to find solutions that aren’t unreliable and don’t create new problems.

Thanks.

Hello!

A lot of times I will make my rigidbody kinematic and manually apply Physics.gravity and move it around myself. This way, you can detect collisions and all that, but you have a lot more control over what actually happens. In my experience, just turning physics on and expecting it to work like the real world is not the case at all. I’ve gotten pretty proficient with RayCasting and SphereCasting too. For pretty much anything that isn’t an open world, this is my preferred method.

If you want to finesse your non-kinematic rigidbody into working properly, then you’ll need to study each weird interaction and try to correct for it. In your example, I know that you can change the properties of physics materials at runtime. Yet even knowing that I’m not sure how your wall would act with modified physics materials. Here the only suggestion I can have is make it easy to test and test often until it “feels” right.

tl;dr: Trying to use physics for everything can be chaos. Try to use a little physics at specific times instead, and calculate things yourself if it needs to be “correct.”

EDIT: I am curious to see what other people’s experience has been!

Gotta agree with Garth Smith there, and I’m about to move down the road of practically using nothing from the PhysX engine (thus calculating practically everything myself for full control in a mech fighting game- while will be made much, much later). Currently, I’m improving a game that’s basically a sphere-based platformer- roll and jump. The rigidbody - with something “simple” like this - works well. However, when I try to do special things (like bouncing platforms/walls or sensitivity), I pretty much have to do it myself.

In the end, Rigidbody is my way to go, but as I create more and more features, it seems like I’ll be making more and more of my features.

(Also, about that mech fighter… Not sure whether or not I should use a character controller or a rigidbody. Still have time to decide that, as both technically can detect collisions. Probably will heavily modify the character controller to the point where it resembles only the collision and then do as I need)

Edit: I have very little practical, current experience with the character controller, so I’m not exactly sure if it’ll be that easy to strip everything off but the collision detection and such. In the end, however, I’ll probably be using that. Additionally, isn’t rotation only locked from either code or in one of the components?

The actual character controller collider is rotation locked and as far as Im aware can’t be unlocked.

Gareth, can you give me an example of your rigidbody implementation? I’m not sure where the casting fits in this.

I have a rigidbody character, and I solved that problem by turning friction off entirely. Instead, I use a downwards raycast to see what’s beneath the character and apply friction-like forces manually when they are grounded. I also have to manually handle the character’s angle limit because it tends to slowly slide down very gentle slopes otherwise.

I also went this route because I also needed to manipulate gravity direction and the standard character controller can’t handle that.

This is the main way I use RayCasts with a rigidbody.

Check out the arrows on Sonic here. The way they have it set up, they can tell when one foot is over a cliff, when Sonic hits his head but not touching the ground, etc… The basics are that you can listen for trigger and collisions when moving the rigidbody around, but if you want to know what’s around you without actually moving (eg: am I touching the ground?) you can raycast around and gather information about your surroundings.

Most of the time I will have all terrain colliders on a “Terrain” layer. Also, Gizmos.DrawRay() is very useful for debugging.

How do you guys deal with forces? Do you use AddForce, set the velocity or MovePosition?

For complex characters, I tend to use MovePosition. My MovementController class has a Vector3 velocity it tracks that I can optionally add Physics.gravity to depending on the characters state.

Some other things I’ll just throw a velocity or force on and let go. Mostly “fire and forget” physics objects such as a bullet, arrows, breakable props… stuff I don’t really care about controlling too exactly. A car rolling down a hill is already a chaotic event. I don’t need to control it.