Jump to content
  • Advertisement
Sign in to follow this  
cuticle

Character Controller

This topic is 3519 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been searching for approaches to emulate platformer-esque character movement with a physics engine. I've managed to dig up a few ideas, but just fragments of a real solution. The main goals I have are to navigate over rough terrain and interact with other bodies. Does anyone have an approach that's worked?

Share this post


Link to post
Share on other sites
Advertisement
It's not too difficult to build something that works reasonably well if you represent your physical character as a cylinder or capsule that moves around, interacting physically with the game level and other objects, and just use a 3D animated mesh for rendering the character

Share this post


Link to post
Share on other sites
Oh, the rendering isn't too important as the project I'm working on is pixellated 2D. (Though I am more interested in the approach rather than implementation.)

But the problem I've had with just using a capsule is movement over rough, dynamically-changing terrain. For instance, movement up stairs, not slipping on shallow inclines, slipping down steep inclines, and being able to walk through narrow passageways.

I've found the "bump and slide" algorithm in some open-sourced Quake 2 code, but I don't know how to use it and still make the capsule able to push and be pushed appropriately. Is it possible to combine the two?

Share this post


Link to post
Share on other sites
I hate to bump this topic, but I've looked around and can't figure out the solution to my problem anywhere.

How can you make a character navigate rough terrain and still interact with the environment?

Share this post


Link to post
Share on other sites
Most character controller solutions that are in major engines (eg: Havok) suffer from exactly the issues you describe. I don't really know of any other solutions to the problem. You could just replace your character controller with essentially a ray cast down to the ground, but that doesn't necessarily play nicely with other character controllers in the world. You wouldn't really be able to bump in to them for instance.

Share this post


Link to post
Share on other sites
So there's no common, elegant solution? I've been looking at
">this video for a sample of what's possible. Do you think that they implemented all those features manually?

Share this post


Link to post
Share on other sites
It's hard to say from the video. Let's take the stairs. In the video they were able to walk up the stairs just fine. But that's also a specifically built test level. Meaning that the stair height might have been (probably was) specifically calibrated to play nicely with the character. Most engines' character controllers have special code to handle stairs. One way it might work is to do a linear cast from an elevated position in front of the character and drop it to the ground. But they only work if the stair height is just so (below a given threshold) and there isn't a ceiling involved. Meaning it's not very robust to an artist or level designer making changes. Like if they want to scale a building by 1.2 they might inadvertently scale the height of the stairs too high and the characters won't be able to walk on them.

One example that's almost pathologically difficult for stair climbing code is a spiral staircase. Like you'd see in a castle tower, where the spiral is very tight. Because near the core of the spiral the stairs turn in to a solid wall.

Share this post


Link to post
Share on other sites
Pushing against other objects can be done by having two radii for the character controller. The inner one is "hard" and the character will just collide and slide against all objects (even if they're really small/light), treating them as static. Any object that penetrates the outer radius will get a force that is proportional to the amount of penetration, up to some maximum (which it gets when it has pushed through to the inner radius). This lets the controller push objects around and get pushed around itself, and it will work when objects get squashed between the controller and the wall. You can also make the inner cylinder just ignore very small objects if you like

I guess something similar would work for the see-saw, using the raycast below the cylinder.

Character-character interactions should be handled all at once (like a physics update, but not in the physics update). Or, you could make it so that each character is "projected" out of any other characters by adding onto the movement for the next update. Then character-character interactions would be soft, which might be desirable.

For climbing steps you can raycast as Numsgil suggests, and then smooth the rendered height of the controller. You can also use this to control the max slope he can walk up/on.

I guess you could use the ground normal to apply a sideways movement that is (a) only applied when he's actually moving for moderate slopes (b) always applied for steep slopes.

Gravity (and inertia) can be implemented by maintaining the velocity of the controller from one update to the next...

You can also make the character controller "stick to the floor" at the top of steps/ramps to stop the character flying at those points, when he's moving fast. You can make it so that he always sticks to slopes that he's capable of walking up, and doesn't stick to steeper slopes. You can do this by extending the raycast mentioned above downwards, and checking what you hit.

Share this post


Link to post
Share on other sites
Thank you; this is what I've been looking for.

1) How would the character be pushed by non-characters? Would you give it a force when something penetrated the outer radius? Or would you make the inner radius be a rigid body?

2) You seem to be talking in terms of the character interacting purely by manually exerting forces. How would you implement constraints like the rope attached to the character?

3) It's just 2D, but narrow passages are pretty important to the level design for the game I'm working on.

I've been able to get pretty good results for spiral-staircase situations with a fairly expensive set of shapecasts: break into vertical and horizontal movement, move up to get over stairs, move horizontal, move down to touch the ground, and on each of these, slide against the wall so you can navigate slopes and ceilings. Are there cheaper methods?

Share this post


Link to post
Share on other sites
Quote:
Original post by cuticle
1) How would the character be pushed by non-characters? Would you give it a force when something penetrated the outer radius? Or would you make the inner radius be a rigid body?


Since the character isn't actually dynamic (it's kinematic really), you can't exactly give it a force. However, you can add things to its movement vector - so when an object comes towards it you could add onto the controller's movement velocity some fraction of the incoming object's relative velocity. The fraction might depend on the object's mass, the amount it has penetrated the outer radius etc.

Quote:

2) You seem to be talking in terms of the character interacting purely by manually exerting forces. How would you implement constraints like the rope attached to the character?


I didn't see that part of the video before. It's actually more like a stick (constant distance constraint), as the character can push the box, and the box can push the character, through the stick. I would do essentially the same as I suggested for the collisions:

1. The character affects the box through applying a spring-like force depending on the error between the box position and the end of the stick

2. The box affects the character by applying a movement request to the character proportional to the error between the character position and the end of the stick.

Quote:

3) It's just 2D, but narrow passages are pretty important to the level design for the game I'm working on.


You can make the inner radius significantly less than the graphical size of the character. You can also modify the character's movement request if the outer radius penetrates the world - so as to softly push the character back away from walls where possible (but he can still squeeze through small passages down to the inner radius).


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!