Flying Character Simulation

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Flying Character Simulation

Post by Garold »

I'm attempting to a add dragon, a floating sorceress plus a few nasty birds.

What's the best way to go about this problem?

I'm currently thinking of using a character controller and applying upward impulses.
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Flying Character Simulation

Post by Norbo »

CharacterControllers aren't particularly valuable for things which don't walk around on the ground. Creating an entity, setting its IsAffectedByGravity to false, and then controlling its LinearVelocity and AngularVelocity directly (which is equivalent to applying impulses) would probably the simplest and best option. Of course, you could keep the entity affected by gravity and apply upward impulses too depending on what kind of behavior you want.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Flying Character Simulation

Post by Garold »

The simpler approach seems sensible.

I've looked through some similar posts: one about a jetpack and another about swimming. From those I worked out I need to do something like this:

Code: Select all

            character.CharacterController.Body.ApplyImpulse(
                character.CharacterController.Body.Position, 
                Vector3.Up * 
                sm.Space.ForceUpdater.Gravity * 
                character.CharacterController.Body.Mass * 
                dt);
I will change it from using a character to just a box as you've suggested as I can't envisage a situation when they will be touching the ground.

However I have another related question. I wanted the Witch to float quite close to the ground. Can I surround her with an additional larger box that I can use for collision testing, rather than casting rays.

In another post you helped me create collision groups, so objects would only interact with static terrain. I need something similar. I would like to see if the larger collision box is colliding but I don't want it to push or hinder any other objects.

Thanks!
BEPUphysics rules my world
http://cloneofduty.com
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Flying Character Simulation

Post by Norbo »

I've looked through some similar posts: one about a jetpack and another about swimming. From those I worked out I need to do something like this:
That would almost work- however, in the direction part:

Code: Select all

                Vector3.Up * 
                sm.Space.ForceUpdater.Gravity * 
                character.CharacterController.Body.Mass * 
                dt
The Vector3.Up term doesn't change anything; instead, negate the gravitational force like so:

Code: Select all

                -sm.Space.ForceUpdater.Gravity * 
                character.CharacterController.Body.Mass * 
                dt
Of course, since this boils down to an acceleration, you could simplify it further to:

Code: Select all

character.CharacterController.Body.LinearVelocity -= sm.Space.ForceUpdater.Gravity * dt;
However I have another related question. I wanted the Witch to float quite close to the ground. Can I surround her with an additional larger box that I can use for collision testing, rather than casting rays.

In another post you helped me create collision groups, so objects would only interact with static terrain. I need something similar. I would like to see if the larger collision box is colliding but I don't want it to push or hinder any other objects.
Using a CollisionRule of NoSolver would do the trick. Contacts are still generated, but no collision response occurs.
Garold
Posts: 60
Joined: Fri Sep 23, 2011 5:17 pm
Location: Liverpool, England

Re: Flying Character Simulation

Post by Garold »

Perfect!

Thank you.
BEPUphysics rules my world
http://cloneofduty.com
Post Reply