#Best method of player movement in 3D

1 messages · Page 1 of 1 (latest)

bold summit
#

I think best option for player movement is not character controller, not rigid body, and not raycasts.

  • Character controller forces you to use capsule and that's bad for some games (standing on edges is funky with a capsule collider because of the rounded bottom, a big problem for a precise platformer for example)
  • rigidbody can be pretty scuffed, i cant explain it that well but it can be glitchy and can go through walls even with all the proper settings and such, and if you want a precise player controller that feels the best then rigidbody isnt that good. physics system isnt that reliable
  • raycasts can be inaccurate for very intricate geometry. Like walking across extremely thin beams. Raycasts have gaps in between them, no matter how small they are still there and may cause problems.

So boxcast is the solution if you want the absolute best, right? (making your own custom player controller using boxcasts)
Thoughts from experts?

sage sigil
#

It seems you are mixing up movement and spatial queries. The character controller uses raycasts under the hood, and you would want to use a spatial query like a raycast or boxcast (or sphere or capsule or whatever you deem correct) with a rigidbody as well.

You are correct that a raycast can cause issues sometimes, especially with intricate geometry. So in a situation where you would walk over thin beams, a wider cast like box or sphere may be preferable.

The custom character controller would still come down to being based off a rigidbody (kinematic or dynamic), the transfrom, or the built-in character controller though. And that choice is going to come down to what feeling of movement you prefer. Rigidbodies certainly need an understanding to get right

I leave you with this flow chart that may help choose between the basic forms of movement

bold summit
sage sigil
# bold summit with boxcast method i mean using transform.position to move the player. i think ...

Boxcast can be used with a rigidbody. It is a spatial query and only indirectly has anything to do with movement.

I would say absolutely not to your second question. The physics engines (PhysX or Box2D for 3d and 2d respectively) are reliable. I vastly prefer rb based movement. And not really sure what issue you have with a round botton of a capsule..

Transform based movement is basically teleportation and doesn't respect physics at all. It can cause all sorts of issues with collisions especially. You need to basically create your own physics solution on top to get it to work right (by predicting the movement for the next frame, checking collision, reacting manually, etc). I would be very surprised if you could make your more reliable while also being as performant as the other engines. But it would be a worthwhile persuit as a learning excersize, and with enough time and effort, you could get to parity for sure

bold summit
sage sigil
bold summit
sage sigil
bold summit
# sage sigil You just make the rigidbody kinematic. Kinematic means you don't respond to forc...

oh ok but then again rigidbodies are unreliable, they have caused so many problems for me in the past with kinematic objects even with continuous collision going through walls and not registering collisions especially when moving fast or at some weird angle or at a weird frame where collision just doesnt work for some reason. there are so many posts of kinematic bullets going through walls, for example https://forum.unity.com/threads/solid-walls-not-always-stopping-bullets.178053/#post-3526805 the solution is just a raycast to see when the bullet should stop. which beats the point of using a rigidbody to handle this stuff.
why is transform movement less preferable? it doesnt have these issues. is it because of performance or?

sage sigil
# bold summit oh ok but then again rigidbodies are unreliable, they have caused so many proble...

Because a Transform DOES have those issues. It is literally teleportation, so bullets will often travel straight through things when fast and small. Transform movement is extremely unreliable.

One frame the transform will be in one position, the next it will be in the next position. There is nothing in between. This can often mean it completely bypasses colliders

I don't know what you mean that raycasting "defeats the point of using a rigidbody". Spatial querying is just part of the work. Making the bullet DYNAMIC instead of kinematic and setting it to continuous can greatly mitigate that though, and often doesn't require raycasting except at extremes. But transform will almost always need it.

Bottom line, transform is unreliable, rigidbody is wayyyyy more reliable. 🤷‍♂️

bold summit
sage sigil
bold summit
#

then how come unity used it for their character controller?

sage sigil
bold summit
sage sigil
bold summit
#

well, if its perfectly fine, then what would be the best? as the question's title suggests.
rigidbody then? its the best despite the issues of going through walls at high speeds?

vale path
sage sigil
bold summit
vale path
bold summit
vale path
#

:d i just telling you what i am doing. You need an answer from an expert but that is what i do usually. I usually depend on Rigidbody's collision detection. If it gave wrong results, then i would mix it with raycasts. Even more? I could mix it with transform.
For a moving platform, yes, why would i need them to re-calculated again? Of course, i would like to know what are the downsides of using a rigidbody for every moving thing tho. I will research now
Oh i found one you may interested in too:
https://forum.unity.com/threads/is-adding-rigidbody-to-every-moving-collidable-object-a-good-practice.253802/

bold summit
#

oh wow can a unity official also confirm this? cause this is groundbreaking knowledge. i've literally been spamming transform.position on every moving thing in my game without a second thought. if this is better for performance and the best practice then i absolutely want to switch to this

vale path
bold summit
#

actually ill post a new thread so it can be seen better cause its a whole new question from this one

vale path
bold summit
#

rigidbody.moveposition should be used for not only the player, but the doors and moving platforms too?

vale path
bold summit
sage sigil
bold summit
#

yeah even with player movement i think its bad to have drag and friction if you want a good feeling snappy player

vale path
#

Depends on the player 😄

sage sigil
vale path
#

You should look at documentation and see what rigidbody offers and test them if you didnt understand very well.

You could test the performance issues by spawning 5000-10000 cube(literally the unity's cube) and move them slowly with transform and rigidbody and compare their performance. FPS will be the one thing that is obvious in that case.

I could say Rigidbody is the best option for player movement since you want colliders to act best. Never used character controller but i see none really suggesting it. Maybe its working well with networking things? A research about that would be good.
Moving a rigidbody's transform.position is literal comedy lmao rigidbody has its own position which is not same with transform.

Unity uses Nvidia PhysX for the physics engine. You could look at PhysX documentation too(its complicated...).

untold olive
#

Character Controller is mostly for prototype or fast/small project.

sage sigil