Proper Character Controller

DschoonmakerDschoonmaker Posts: 188Member

I have a few questions about how to make a good character controller. I've seen some posts about this before, but none of them really answered my questions. First, sliding on slopes. I can't find a way to eliminate all sliding. If I set the max slope angle to the slope angle the body is currently on, that removes most sliding, but there's still a little bit of sliding that would be unacceptable in a finished game.
Also, stairs. Kinematic body gets stuck on the smallest stairs. A lot of people just use a sloped collision for the stairs, but there would still be plenty of little steps/objects for characters to get stuck on. I didn't try much to fix this, I couldn't think of many solutions.
Does anyone know how to fix these? Everyone has these problems, but I've never seen them solved properly.

Comments

  • andersmmgandersmmg Posts: 3Member

    I got my controller working pretty well, here's what I did.

    For stairs, I have a RayCast to detect if there's a stair in front of the player. I check the normal and see if the angle is as a stair should be. If it is, I just basically make the player jump a specified value separate from normal jump value. It makes stairs smoother without having to press the jump key a bunch, but still feels a lot more like stairs.

    For slopes, I know it checks the angles to make sure you can't climb up a super steep hill, but that seems similar to what you're doing. One way you could do it is basically lock the over transforms when the player is falling, so it'll only fall on the Y dimension. There are multiple ways this could be done.

  • DschoonmakerDschoonmaker Posts: 188Member

    I'll try the stairs, I failed with that solution before, but I can probably do it if I try again. For the slopes, if you lock the X and Y position, it can make the character fall through the ground, because of the extra Y movement down the slope. Did you do this some other way?

  • DschoonmakerDschoonmaker Posts: 188Member
    edited May 20

    I fixed slope sliding and am working on stairs, the main problem with the stairs is getting smooth movement up stairs, it can look really bad if the player jitters up the stairs.

    Another problem with kinematicbody is rigidbody physics. I found an article about that: http://kidscancode.org/godot_recipes/physics/kinematic_to_rigidbody/

  • SIsilicon28SIsilicon28 Posts: 647Moderator

    What games sometimes do with stairs is instead of having collision shape accurately take on a stair shape, they approximate it with a ramp-like shape instead.

  • DschoonmakerDschoonmaker Posts: 188Member

    A lot of games do have individual stair collisions. You can tell if you knock some rigid body down the stairs.
    I could use a ramp for stairs, but there are still sometimes little obstacles to walk over, I think it's just better if players can get over small bumps.

  • SIsilicon28SIsilicon28 Posts: 647Moderator
    edited May 21

    @SIsilicon28 said:
    What games sometimes do with stairs...

    Super Mario 64 for example used the ramp trick for the main room's staircase. The other stairs however were real.

  • TwistedTwiglegTwistedTwigleg Posts: 2,450Admin

    I'm not sure how well it would perform, but another thing to consider is having separate collision shapes for the player and for Rigidbody nodes. The player could use a simplified ramp shape to allow for easy player movement, while Rigidbody nodes could use a more complex stair shape with the bumps and the like. Theoretically you could just place the collision shapes on different collision layers, and then configure the player and Rigidbody nodes accordingly.

  • DschoonmakerDschoonmaker Posts: 188Member

    @SIsilicon28 said:

    @SIsilicon28 said:
    What games sometimes do with stairs...

    Super Mario 64 for example used the ramp trick for the main room's staircase. The other stairs however were real.

    Huh, I wouldn't have thought a game that old would use real stairs.

    I don't think I understand your solution, @TwistedTwigleg , but I do think I should add stair support.

  • DschoonmakerDschoonmaker Posts: 188Member

    The last thing I can think of is standing on platforms. I set up a little test for this, it has a kinematic body controlled with an animation player to move back and forth. If I walk on it, platform movement works pretty well by default, but there's a little bit of movement; the player isn't perfectly synced to the ground movement. I think the 2D version of kinematic body has a built in solution to this, but 3D doesn't. Is it possible to solve this?

  • SIsilicon28SIsilicon28 Posts: 647Moderator

    Maybe check this out. The tutorials are in Unity, and also are being used on a Rigid Body, but it might have some useful information concerning this matter.

  • TwistedTwiglegTwistedTwigleg Posts: 2,450Admin

    @Dschoonmaker - The idea is basically to have two collision shapes, one for the player and another for everything else. The player collision shape would use a simple ramp without each individual step, removing the issue of having to have the player handle the bumps created by the stairs. The other collision shape would have the bumps caused by the stairs, it would not be a smooth ramp, and could be used by all of the Rigidbody nodes. It is basically a middle ground between using ramps and full stair collision shapes.

  • DschoonmakerDschoonmaker Posts: 188Member

    @TwistedTwigleg What do you mean "another for everything else"? It sounds like you mean two different collision shapes for the player?

  • SIsilicon28SIsilicon28 Posts: 647Moderator

    Actually he means two different collision shapes for the stairs. Although in retrospect it's more like two different bodies. You see, physics objects collide with other physics objects as long as they are in the same layer. You can make an object that can collides with one object in a layer, but not another in a different layer.

  • TwistedTwiglegTwistedTwigleg Posts: 2,450Admin

    @SIsilicon28 said:
    Actually he means two different collision shapes for the stairs. Although in retrospect it's more like two different bodies. You see, physics objects collide with other physics objects as long as they are in the same layer. You can make an object that can collides with one object in a layer, but not another in a different layer.

    Yeah, that's exactly what I am meaning!
    The idea being that you get the best of both worlds. Characters can use the simple collision body and shape, while Rigidbody nodes (and others) can use the more accurate, complex collision body and shape.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file