Arcanor
19-02-2008 04:34:20
I'm looking for a beginner-level HOWTO, tutorial, or sample code covering implementation of the NxOgre::Character and CharacterController classes to create a maneuverable player object for an RPG or FPS game. There doesn't seem to be anything in the shortguide, or in Cake, and I've only found small snippets here in the forums.
Is there an implementation I can review somewhere so I can see how it's commonly done in NxOgre?
Darksecond
19-02-2008 10:17:30
i also have been looking for this kind of information. mostly on how to get animations working correctly (for example jumping). some tutorials would be nice indeed!
Arcanor
19-02-2008 14:02:43
Well maybe I can get this thread rolling a bit by posting what I've got so far.
In my application, I have implemented the following:
- a generic container class called ArcObject, which keeps pointers to various things about an entity, including the associated Ogre::Entity, the NxOgre::Character or NxOgre::Body as appropriate, various state flags, speed variables, etc.
- a world manager singleton object which among other things keeps a list of all ArcObjects.
- a custom main program loop (in lieu of a frame listener) which calls ArcObject::update() each frame for each object in the list.
So, to implement the PhysX kinematic character controller I found some things here and there in these forums and cobbled something together, and I'm hoping for some comments to improve my code.
To implement the player character: in my world manager I have implemented an ArcWorldMgr::CreateCharacter() function as follows (note that this does not currently support character animation, but that will be added eventually):
ArcObject* ArcWorldMgr::CreateCharacter(Ogre::String entName, Ogre::String meshName, Ogre::Vector3 position, Ogre::Quaternion orientation)
{
ArcObject* obj = new ArcObject();
mvObjects.push_back(obj);
NxOgre::Character* character = mScene->createCharacter(entName, NxOgre::Pose(position, orientation), "type: capsule");
character->attachMesh(meshName);
character->createNode();
obj->setCharacter(character);
obj->setEntity(character->getEntity());
return obj;
}
To implement movement: in my ArcObject::update() code (which is called each frame), I am currently using this, which seems to be working okay as a start:
if (mCharacter != 0)
{
if (mbWalk)
{
//mCharacter->addMovement(NxOgre::Character::DR_StepLeft);
mCharacter->setRawNextMovementDirection(mWalkSpeed * NxVec3(0, 0, -1));
}
if (mbWalkBackwards)
{
mCharacter->setRawNextMovementDirection(mWalkSpeed * NxVec3(0, 0, 1));
}
if (mbTurnRight)
{
mCharacter->getNode()->yaw(Ogre::Radian(-mTurnRate));
mCharacter->setDirection(mCharacter->getNode()->getOrientation());
}
if (mbTurnLeft)
{
mCharacter->getNode()->yaw(Ogre::Radian(mTurnRate));
mCharacter->setDirection(mCharacter->getNode()->getOrientation());
}
}
There are still some problems with this implementation. First of all, obviously, it's very incomplete. It doesn't include jumping, or sidestep/strafe. It also doesn't compensate for the time elapsed each frame (although I do have that information available).
I'm also very interested to know if other people's implementation differs from mine, and if I could be doing things more efficiently. Obviously this is an important piece of code because it will be called in every single object, every single frame. I need it to be as efficient as possible.
How can I improve my implementation? Thanks for taking the time to read through all this!
lonwolf
25-06-2008 19:23:29
Heya.
Can you post here how do you make the character collide and push objects? Because the physx training programs uses pre defined colision groups
enum GameGroup
{
GROUP_NON_COLLIDABLE,
GROUP_COLLIDABLE_NON_PUSHABLE,
GROUP_COLLIDABLE_PUSHABLE,
};
however these groups are not implemented in NxOgre. Any help? i am using
NxOgre::CharacterParams mCP;
mCP.setToDefault();
mCP.mType=NxOgre::CharacterParams::CT_Capsule;
mCP.mDimensions=NxVec3(5,10,5);
player_char = mScene->createCharacter("PlayerCharacter",NxOgre::Pose(player_node->getWorldPosition()+Vector3(0,50,0),player_node->getWorldOrientation()), mCP);
player_char->attachMesh("ninja.mesh");
player_char->createNode();
player_char->getNxController()->setCollision(true);
player_ent = player_char->getEntity();
player_node = player_ent->getParentSceneNode();
player_node->scale(0.1,0.1,0.1);
player_node->yaw(Radian(Degree(180)));
anim_state=player_ent->getAnimationState("Idle3");
anim_state->setLoop(true);
anim_state->setEnabled(true);
created=true;
Body* b = mScene->createBody("ground; ocean_surface.mesh", new NxOgre::CubeShape(400,1,400),NxOgre::Pose(Vector3(0,0,0)),"mass: 0");
my ninja is not coliding with the "terrain".. any suggestions? i am new to NxCharacter and i need to use it otherwise i should make my own NxCharacter..
also, i can move it (lol), i have implemented forward movement for now.. but i don't get it.. how do i use those groups if defined???