CharacterController vertical glue

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
stino
Posts: 24
Joined: Sun Apr 14, 2013 9:05 am

CharacterController vertical glue

Post by stino »

Hi,

I'm trying to make the chacacter controller toggleable so that I can switch to flying mode.

Currently it looks like I managed to get the flying correct by disabling the HorizontalMotionConstraint and VerticalMotionConstraint by setting their IsActive property to false.

This seems to working, but for some reason, if i land on the ground and try to vertically take off, the player entity starts to shake violently until i disable the vertical impulse again. Like something is still trying to hold it on the ground.

Is there something else I need to disable, or is setting IsActive not enough to disable the constraint completly?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController vertical glue

Post by Norbo »

That's probably downstepping. If a character had support in the previous frame and doesn't in the current frame, it will scan downwards for a support. If it finds one, it teleports down.

This can be disabled by finding this line in the CharacterController:

Code: Select all

                if (StepManager.TryToStepDown(out newPosition) ||
                    StepManager.TryToStepUp(out newPosition))
                { ... 
and simply commenting out the TryToStepDown part. This works just fine, is a bit faster, and is actually more physically correct. The only reason explicit downstepping exists is to support the common FPS-style 'run down stairs at 40mph without flying off' use case.
stino
Posts: 24
Joined: Sun Apr 14, 2013 9:05 am

Re: CharacterController vertical glue

Post by stino »

Haha, 'run down stairs at 40mph without flying off'. That, and the up stepping with tiny stairs: 10 forward is 160 up :D.

The character is seemingly behaving correct when I toggle the constraints, but this escaped my toggling. Not entirely sure if I should disable it completely, or include it in the toggle.

I suppose it won't interfere with normal jumping and walking :D ?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController vertical glue

Post by Norbo »

The character is seemingly behaving correct when I toggle the constraints, but this escaped my toggling. Not entirely sure if I should disable it completely, or include it in the toggle.

I suppose it won't interfere with normal jumping and walking :D ?
Jumping and walking around will indeed behave as expected. In fact, when walking down steps (at a reasonable speed such that gravity can keep up), the character will still keep traction even though it will technically be 'falling' after each step. The character ends up still feeling controllable.

For reference: in our own projects, I typically disable the teleportation-based upstepping and downstepping and use either CharacterControllers with large margins (capsule-ish instead of cylinder-ish) or SphereCharacterControllers. With those, "upstepping" and "downstepping" are handled implicitly through the shape of the character. This can be more natural in some cases, and maintaining physical continuity is nice when dealing with a lot of dynamic interactions.
Post Reply