Flying npc with hkpCharacterRigidBody

Flying npc with hkpCharacterRigidBody

Hi,I'm currently implementing a flying npc with hkpCharacterRigidBody, before this i used a simple sphere-shaped phantom, which worked, but was a bit jerky. Now i try to unify all npc types under the flag of the rigidbody charctrling.
What I did:- sethkpCharacterRigidBodyCinfo::m_maxSlope to PI/2-hkpCharacterInput::m_characterGravity.set(0,0,0);- calledhkpCharacterRigidBody::checkSupport()With theese the npc moves, unsupported (slowly) in the air, but only horizontaly.
Tryed NOT to callcheckSupport(), and always fillhkpCharacterInput myself, always givinghkpCharacterOutput::m_supportedState = hkpSurfaceInfo::SUPPORTED;This made the movement faster, but no going up or down.I discovered that the Y part of velocity always 0 in the output (hkpCharacterOutput).The hkpCharacterStateManager has both theHK_CHARACTER_ON_GROUND andHK_CHARACTER_IN_AIR states.So any help is welcome.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havok_josh's picture
Best Reply

Hi hdevfp!There are lots of ways to do this, but they all come down to the idea that you can just set the velocity directly on the hkpCharacterRigidBody (based on how you implement "flying"). For example, I just modified theDemo\Demos\Physics\UseCase\CharacterControl\CharacterRigidBody\ControlCharacterRb\ControlCharacterRbDemo.cppto change gravity when the player presses "H" with this snipped in stepDemo():

			if ( keys.getKeyState('H')) {

				input.m_characterGravity.set(0,0,0);

			}

			else {

				input.m_characterGravity.set(0,0,-16);

			}
This has the effect of letting the character "fly" when I press 'H" after a jump because the character still had some Z velocity when gravity was turned off. Obviously, you can get A LOT more sophisticated but that should suggest a way forward. I didn't need to modify any of those other parameters you mentioned to get this effect but play around with it and let us know how it works.Good luck!-Josh

Josh Developer Support Engineer Havok www.havok.com

Hi, thanks for the tip playing with the SDK demo!
It seems the character is flying 'properly', until it touches the ground, then sticks to the ground-geometry, which is expected for non-flying controllers. Even without gravity (holding 'H' in your example) goes up and down on a ramp. On gound, gravity does not matter much, velocity is computed from hitpoints/normals i think. That makes flying stuff stick to ledges..
Adding this solves this problem:input.m_surfaceInfo.m_supportedState = hkpSurfaceInfo::UNSUPPORTED;This does not let 'ground mode' kick in.Setting vertical velocity is really easy after this, as you said:
- setting ribidbody velocity directly- using gravity with proper positive/negative values.Cheers.

Login to leave a comment.