Make the CharacterController grab edges/climb mountains

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Arthur Gibraltar
Posts: 6
Joined: Sat Jun 23, 2012 5:01 am
Location: Brazil
Contact:

Make the CharacterController grab edges/climb mountains

Post by Arthur Gibraltar »

Hi, Norbo! My game is finally growing up! And much thanks to you. :mrgreen:

So now I've got a question about the CharacterController. I implemented and changed it so it can jump while crouching, and other little things just by the variables.

But reading and understanding all those math and physics calculations made me confuse, it's too difficult for me for now. :oops:

So I can see it can step up or down while walking and detecting the height of the step (with the StepManager). And it's great! :!:

But how would I calculate it so it could grab marked walls, as if they were cracks on the mountain, and hold there until the player releases a button? :?:

And how can detect that the CharacterControler jumped at least half higher than a block and that it can automatically grab and "step up" on it, "à la" "Tomb Raider"? :?:

I'd have to make another class with similar functions of the StepManager. But I don't know where to start from, if you can give me any tip it would help a lot. Thank you!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Make the CharacterController grab edges/climb mountains

Post by Norbo »

But how would I calculate it so it could grab marked walls, as if they were cracks on the mountain, and hold there until the player releases a button?
There are two steps to this: first, the surface must be detected, and second, the character must attach to it.

To detect the surface, the SupportFinder.SideContacts might be usable. Depending on the geometry of the surface and the desired behavior, this might not work very well since it requires the character to touch the surface rather than merely come near it.

Another option is to cast a ray or multiple rays towards likely candidates in the immediate vicinity. The QueryManager.RayCast could assist with this- it already has the pruned set of objects near the body. The ray direction could be chosen heuristically based on movement direction, or a large number of brute force samples could be used.

To attach to a detected surface, there are a few options. The simplest is just to set the velocity of the character such that it doesn't move relative to the attachment. This is pretty easy for a static attachment, but becomes more complex for a dynamic object. The desired velocity of the character would be based on the linear and angular velocity of the parent, along with the offset. However, since setting the character's velocity doesn't apply any force to the parent object, the parent's motion will be unaffected.

A more physically consistent approach is to use a constraint. Something like a WeldJoint (which is just a BallSocketJoint and NoRotationJoint combined) would work. However, since the character can't rotate at all by default, just using a BallSocketJoint alone with the anchor at the character's center of mass would be an option- using a NoRotationJoint with a CharacterController would stop the rotation of the parent object.

The lack of rotation in the character controller will cause other issues if the parent object rotates into collision with the character, though. If possible, avoid this case. If it ends up being necessary, options include either using a rotating proxy while attached to an object, or modifying the character to allow physical rotation (which is doable, though not extremely simple).
And how can detect that the CharacterControler jumped at least half higher than a block and that it can automatically grab and "step up" on it, "à la" "Tomb Raider"?
It sounds like you might be able to accomplish something similar by just removing the condition that stops stepping from working when the character lacks traction. It's in the StepManager.TryToStepUp function.
Arthur Gibraltar
Posts: 6
Joined: Sat Jun 23, 2012 5:01 am
Location: Brazil
Contact:

Re: Make the CharacterController grab edges/climb mountains

Post by Arthur Gibraltar »

Thanks, Norbo!! You are brilliant.

I'm going to start learning these methods better and I'll try to implement it. They are complicated for me, I started using your physics engine a short time ago, and it's very well made, so you had to know physics itself a lot before creating it, and I don't know much yet.

Step by step I'm building my first 3D game. I've got the sun and the moon, a simple voxel drawer (without the map generation yet), rain and clouds (sky dome), and the physics using BEPU. Now I'm going to try this for a better character movement.

Thank you very much! :mrgreen:
Post Reply