Page 1 of 1

Flying Character Simulation

Posted: Tue Nov 06, 2012 9:11 pm
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.

Re: Flying Character Simulation

Posted: Tue Nov 06, 2012 9:19 pm
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.

Re: Flying Character Simulation

Posted: Tue Nov 06, 2012 9:45 pm
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!

Re: Flying Character Simulation

Posted: Tue Nov 06, 2012 9:52 pm
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.

Re: Flying Character Simulation

Posted: Tue Nov 06, 2012 10:16 pm
by Garold
Perfect!

Thank you.