Q about CharacterController Vertical Speed.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
6thVenom
Posts: 12
Joined: Mon Sep 03, 2012 6:31 pm

Q about CharacterController Vertical Speed.

Post by 6thVenom »

Hi, i'm a long time reader, first time poster :)
First of all, Norbo, thanks you so much for BEPU physics, it's truly amazing.

Then comes questions:
1) Using the last build CharacterController, i'd like to know where are the values, if any, to control vertical speed, or how could i possibly modify the VerticalMotionConstraint (as i think it should be there, right?) to dynamicly change this value on the fly.
- The goal is to clamp the jumping/falling speed in a low gravity space.

2) How could i add/control the air friction/air resistance in a zero gravity space? like a drone floating in the air, moving only when you order it, stopping otherwise.
- The goal is to 'auto stop' the floating entity, allowing it to move only on impulses.

Thanks for any help on the subject.
Greg.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Q about CharacterController Vertical Speed.

Post by Norbo »

First of all, Norbo, thanks you so much for BEPU physics, it's truly amazing.
Thanks and you're welcome :)
1) Using the last build CharacterController, i'd like to know where are the values, if any, to control vertical speed, or how could i possibly modify the VerticalMotionConstraint (as i think it should be there, right?) to dynamicly change this value on the fly.
- The goal is to clamp the jumping/falling speed in a low gravity space.
The vertical motion constraint stops a character from separating from its support. It does not do anything when the character is not standing on a surface.

You can explicitly clamp falling speed of any entity by directly changing its linear velocity. If the Y component of the entity.LinearVelocity exceeds the desired maximum in magnitude, set it to a smaller value.
2) How could i add/control the air friction/air resistance in a zero gravity space? like a drone floating in the air, moving only when you order it, stopping otherwise.
- The goal is to 'auto stop' the floating entity, allowing it to move only on impulses.
Setting a high entity.LinearDamping would do something similar. If you would like more control, you could directly manage the entity.LinearVelocity as mentioned before.
6thVenom
Posts: 12
Joined: Mon Sep 03, 2012 6:31 pm

Re: Q about CharacterController Vertical Speed.

Post by 6thVenom »

Tell us the truth, you sleeping here right? :D

Oh, i thought the vertical motion constraint was a bit more complex/sophisticated, like horizontal motion constraint is!

I'll do something like you said, as i always thought there was some *magical* air friction going on under the hood.
Any advice on the subject? I suppose i'll need to do some sort of counter impulses, one inverse gravity continuously, and some lerps between actual entity.linearVelocity and zero. Where should i put it?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Q about CharacterController Vertical Speed.

Post by Norbo »

i always thought there was some *magical* air friction going on under the hood.
Entity.LinearDamping defaults to 0.03, so there is a bit of magical air friction unless it's manually set to 0. The character does so in its constructor so that the horizontal motion constraint doesn't have to fight an extra force.
Any advice on the subject? I suppose i'll need to do some sort of counter impulses, one inverse gravity continuously, and some lerps between actual entity.linearVelocity and zero. Where should i put it?
You can prevent an entity from having gravity applied to it by setting the entity.IsAffectedByGravity property to false.

Clamping falling speed would look something like this:

Code: Select all

            var velocity = entity.LinearVelocity;
            if (velocity.Y < -50)
            {
                velocity.Y = -50;
                entity.LinearVelocity = velocity;
            }
Stopping all linear motion can be done by just setting the linear velocity to the zero vector. Multiplying the linear velocity by some fixed factor (say, 0.95f) every frame where you aren't trying to move is one easy and cheap way to slow things down smoothly. A lerp is another option.

A slightly more involved option would be to compute the 'unwanted' motion at any given time, and apply an impulse/change the velocity to specifically remove that motion. If you aren't trying to move, then the unwanted motion is any and all motion. If you are trying to move, then the unwanted motion is any side-to-side (and optionally, going faster than a maximum speed). The unwanted motion can be immediately removed by subtracting it from the linear velocity, or you can remove it over time using a lerp/exponential falloff/explicit counter impulse.

The velocity changes can be put just about anywhere. Just doing it external to the space update should work fine. If you want, you could put it into the forces stage of the space update using an IDuringForcesUpdateable or hooking onto the starting/finishing event of a nearby update stage in the Space, but that's generally only useful for systems with extremely tight timing requirements.

One final option would be to use a SingleEntityLinearMotor (or the EntityMover which uses a SingleEntityLinearMotor internally) to handle the motion. Specify a goal (position or velocity wise), configure the motor strength, and it will do the rest.

Edit:
Tell us the truth, you sleeping here right?
Maybe...
6thVenom
Posts: 12
Joined: Mon Sep 03, 2012 6:31 pm

Re: Q about CharacterController Vertical Speed.

Post by 6thVenom »

I think i'll go for the simplest form possible, as it should only be used a few times in the (prototype of my) game. so i'll go for something really similar to the code you posted, as i already implemented it in the Chara' controller update method while i was waiting. works pretty good for my purpose.

To stop the linear motion in the second scenario, i'll go for a simple: SpeedLinear = Lerps(SpeedLinear, Vec3.zero, AirFrictionValue * dt)

One last thing, could you please point me any link to a BEPU physics logo, or is the "344x240 png" texture is the only one available? Ultimately, the goal would be to have materials to show while pre-loading assets, or a nice logo to show at the beginning of a trailer, if you're ok with that. I hope to make a short clip of the game soon (the game is a Contra/MetalSlug-like rendered in 3D).

Anyway, thanks you for your time.
Greg.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Q about CharacterController Vertical Speed.

Post by Norbo »

One last thing, could you please point me any link to a BEPU physics logo, or is the "344x240 png" texture is the only one available? Ultimately, the goal would be to have materials to show while pre-loading assets, or a nice logo to show at the beginning of a trailer, if you're ok with that. I hope to make a short clip of the game soon (the game is a Contra/MetalSlug-like rendered in 3D).
Here's my usual speech about the logo:
It is indeed perfectly acceptable to use the logo- so long as you don't make us look bad or evil (e.g. "Powered by BEPUphysics: A library created by murderers of puppies and kittens, trust me, I watched them do it, they're horrible people") or use it to promote things that we wouldn't want to promote (e.g. "You should murder puppies and kittens; BEPUphysics agrees!").

Here's a huge version that can be downscaled to whatever size needed:
http://www.bepuphysics.com/storage/site ... %20big.png

If there's something potentially evil or heinous about the way the logo is used and you're not sure if it's okay, just let me know and I'll tell you if it's okay :)
6thVenom
Posts: 12
Joined: Mon Sep 03, 2012 6:31 pm

Re: Q about CharacterController Vertical Speed.

Post by 6thVenom »

Wow! this huge one is exactly what i was looking for!
(you should provide a link somewhere on http://www.bepuphysics.com/ maybe)

I'm not making an Evil simulator, don't worry! :)

Thanks,
Greg.
Post Reply