Character/Rigidbody naming

Dboy85

12-02-2012 22:57:03

Hey all, What's the best practice for setting the name of a character in Bloody Mess. I'm trying to get to grips with ray casting and I'm trying the following:


// TODO: RAY CAST AND FOLLOW PLAYER IF PATH IS CLEAR.
m_RaySource = m_Enemies.at(count)->getAnimChar()->getPosition();
m_RayDirection = (m_Enemies.at(count)->getAnimChar()->getPosition() - m_pPlayer->getPosition()).normalise();
NxOgre::Ray( NxOgre::Vec3(m_RaySource.x,m_RaySource.y,m_RaySource.z) , NxOgre::Vec3(m_RayDirection.x ,m_RayDirection.y,m_RayDirection.z) );

// Find the closest object that intersected the ray between the Player and Zombie.
NxOgre::RaycastHit hit = m_renderSys->getScene()->raycastClosestShape(m_Ray, NxOgre::Enums::ShapesType_Dynamic);

if(hit.mRigidBody)
{
Ogre::String name = hit.mRigidBody->getName();// Empty as usual.

if( hit.mRigidBody->getName() == "Player" )// etc...
{
// your code goes here
int x = 0;
}
}


hit.mRigidBody->getName() is empty so I'm obviously setting up the characters wrongly.

Ogre::Entity * mEnt = mSceneMgr->createEntity(name,meshName);
mNode->addEntity(mEnt);
...
mCharacter = mRenderSystem->createAnimatedCharacter( position , Ogre::Radian(0), mNode, desc);
So have I set up the character correctly in a way that I can retrieve the name from it at will?

If anyone has a code snippet that would be super, thanks.

P.S Another character related question. When I want to set a body as collide-able non pushable in the scene I set up the body description but it seems to ignore
this upon collision with an animated character. The body moves as if it was set to be pushable and I tested it by dropping another body on it and it didn't move so its the character.
I tried to set the body's dynamic flag as freeze position as a work around but then the collision doesn't happen at all.

Any help appreciated thanks

Dboy85

13-02-2012 18:46:30

I just added in a function to the Rigidbody class to set the name as a work around.

Still have no idea about the second question I posted.

saejox

17-02-2012 23:42:18

Critter::AnimatedCharacterDescription desc;

if(character->physxShape == "capsule")
{
// desc.mShape = NxOgre::SimpleCapsule(character->physxValue1,character->physxValue2);
}
else if (character->physxShape == "box")
{
//box not implemented in critter yet!
desc.mShape = NxOgre::SimpleBox(NxOgre::Vec3(character->physxValue1,character->physxValue2,character->physxValue3));

}



desc.mCollisionMask |= (NormalWall << 1);
desc.mCollisionMask |= (HookableWall << 1);

desc.mMaxGroundSpeed = 17.0f;
//id = index;

desc.setJumpVelocityFromMaxHeight(NxOgre::Constants::MEAN_EARTH_GRAVITY.y, 0.1);

mNPC = mRenderSystem->createAnimatedCharacter(Ogre::Vector3(pos.x, pos.y, pos.z) , Ogre::Radian(0), character->pack + ".mesh",desc);

mNPC->getShape(0)->setGroup(NPC);

// mNPC->getShape(0)->setFlag( NxOgre::Enums::ShapeFlags_DisableRaycasting , true);
mNPC->setInteractionFlag(NxOgre::Enums::CharacterControllerInteractionFlag_Exclude);

if(LevelLoader::getSingletonPtr()->Creatures[monsterID].material != "")
{

static_cast<Entity*>(mNPC->mNode->getSceneNode()->getAttachedObject(0))->setMaterialName(LevelLoader::getSingletonPtr()->Creatures[monsterID].material);

}

saejox

17-02-2012 23:53:10

here is how i create an npc
do not forget to add a collisionmask. AnimaterCharacter uses a whole different collision system. it's not enough to just calling setGroup

Critter::AnimatedCharacterDescription desc;
desc.mShape = NxOgre::SimpleBox(NxOgre::Vec3(character->physxValue1,character->physxValue2,character->physxValue3)); // shape is capsule by default in critter
desc.mCollisionMask |= (NormalWall << 1);
desc.mMaxGroundSpeed = 17.0f;
desc.setJumpVelocityFromMaxHeight(NxOgre::Constants::MEAN_EARTH_GRAVITY.y, 0.1);
mNPC = mRenderSystem->createAnimatedCharacter(Ogre::Vector3(pos.x, pos.y, pos.z) , Ogre::Radian(0), character->pack + ".mesh",desc);
mNPC->getShape(0)->setGroup(NPC);


here is a how a wall is created

NxOgre::BoxDescription bd(obj->physxvalueX,obj->physxvalueY,obj->physxvalueZ);
bd.mGroup = NormalWall;
mScene->createSceneGeometry( bd, (NxOgre::Vec3) pos );
//TODO, add a mesh with Ogre

createSceneGeometry is for objects that never move. they provide collision, but they dont move themselves.

look at the Physx documentation. it's a chm file that came with physx sdk.
good luck.