Character movement

marceloharmonia

10-07-2009 21:34:20

Hi, I read the documentation of PhysX and tried use NxCharacter to apply a physics to character, but I can not add gravity to it. The PhysX docs said that I have to apply gravity through of move function and tried to use this code in framelistener:

NxVec3 d(0,0,0);
if(mKeyboard->isKeyDown(OIS::KC_UP)) d.z = -10*time;
if(mKeyboard->isKeyDown(OIS::KC_DOWN)) d.z = 10*time;
if(mKeyboard->isKeyDown(OIS::KC_RIGHT)) d.x = 10*time;
if(mKeyboard->isKeyDown(OIS::KC_LEFT)) d.x = -10*time;
NxF32 sharpness = 1.0f;
NxU32 collisionFlags;
d.y = -9.8*time;
control->move(d, COLLIDABLE_MASK, 0.000001f, collisionFlags, sharpness);
NxVec3 NxPos = act->getGlobalPosition();
Ogre::Vector3 offset(4,40,0);
mPlayerNode->setPosition(Ogre::Vector3(NxPos.x,NxPos.y,NxPos.z) - offset);

But the character Y axis decreases continuously, and I want know how I detect the collision of the character with floor (or terrain) and do the d.y = 0, doing the character don't through the floor (or terrain)? I tried use callback, but this don't work...
Thanks!

fibre3d

13-07-2009 11:36:17

What's the value of your COLLIDABLE_MASK? If it's -1, it should be able to detect all the collisionGroups in the scene. Or if u want to collide with only objects in group (x), use (1<<x) as the mask. Dunno if this helps tho.

marceloharmonia

13-07-2009 16:09:39

What's the value of your COLLIDABLE_MASK?
I'm using this value to COLLIDABLE_MASK. I tried with -1 too, but don't work.
enum GameGroup
{
GROUP_NON_COLLIDABLE,
GROUP_COLLIDABLE_NON_PUSHABLE,
GROUP_COLLIDABLE_PUSHABLE,
};

#define COLLIDABLE_MASK (1<<GROUP_COLLIDABLE_NON_PUSHABLE) | (1<<GROUP_COLLIDABLE_PUSHABLE)

fibre3d

14-07-2009 09:39:33

Really dunno, but if ur capsule's going through the terrain, my guess is that it's cos the terrain's group wasn't explicitly set, so it's default group would be 0 (NON_COLLIDABLE). If you put break points within any part of ur if statement...
if( collisionFlag & NXCC_COLLISION_DOWN )
{
d.y = 0;
}
...and it don't get called, it's probably that. no collision detection btw ur capsule and terrain. then again, maybe not! :D

marceloharmonia

14-07-2009 13:08:23

Oh, cool now when it collide with a box the gravity is changed to 0, but when It colide with a plane (I'm using this) the gravity isn't changed, Why?
Thanks, You're helping me very much.

betajaen

14-07-2009 13:19:17

Characters don't collides with planes.

marceloharmonia

17-07-2009 12:31:37

Characters don't collides with planes.
Oh, thank you!
How can I do my character jump?