[SOLVED] Basic movements

spacegaier

06-03-2008 21:17:15

Hi,

as I'm just starting I need to know the basic process of moving a player, or better: what is done by NxOgre what was done by Ogre before?

Step 1: I initialised Ogre and NxOgre.
Step 2: Created 2 OgeMeshes: a player and a kind of ground.
Step3: Created a NxOgre::Body:
m_pPlayer1Body = m_pNxScene->createBody("Player1",new NxOgre::CubeShape(1.0f),Vector3(0,0,0),"mass: 1");

How can I now move this player? Do I have to add a force and is the player then automatically move? Or how is this basicly going on?

Do I have to care of rendering myself?

betajaen

06-03-2008 21:50:20

That's not how you do players. You use Characters for representation of Humans.

spacegaier

06-03-2008 21:53:27

Okay, I was able to answer some of the above questions on my own by experimenting:

I don't have to render the things manuallay as attached to an FrameListener.

The main reason why it did not work was the fact, that my createBody function wsa filled with less information. The functions also needs the name of the mesh to use for the body.

m_pPlayer1Body = m_pNxScene->createBody("Player1;Player.mesh",new NxOgre::CubeShape(1.0f),Vector3(0,0,0),"mass: 1");

However I got the next problem. As long as I only use one arrow key to move my player everything is fine. But as soon as I press two of them at the same time my body is pitching, rolling and yawing as it seems to be torn in two directions.

This is my code atm:

if(m_pKeyboard->isKeyDown(OIS::KC_LEFT))
{
Vector3 pos = m_pPlayer1Node->getPosition();
//m_pPlayer1Node->setPosition(pos.x-1, pos.y, pos.z);
m_pPlayer1Body->addForce(Vector3(-10,0,0));

}

if(m_pKeyboard->isKeyDown(OIS::KC_RIGHT))
{
Vector3 pos = m_pPlayer1Node->getPosition();
//m_pPlayer1Node->setPosition(pos.x+1, pos.y, pos.z);
m_pPlayer1Body->addForce(Vector3(+10,0,0));
}

if(m_pKeyboard->isKeyDown(OIS::KC_UP))
{
Vector3 pos = m_pPlayer1Node->getPosition();
//m_pPlayer1Node->setPosition(pos.x, pos.y, pos.z-1);
m_pPlayer1Body->addForce(Vector3(0,0,-10));
}

if(m_pKeyboard->isKeyDown(OIS::KC_DOWN))
{
Vector3 pos = m_pPlayer1Node->getPosition();
//m_pPlayer1Node->setPosition(pos.x, pos.y, pos.z+1);
m_pPlayer1Body->addForce(Vector3(0,0,+10));
}


What to do against this behaviour?

EDIT: My player is not a human! It's just a simple model (a modified cylinder with a sphere on its top). Use characters however?

betajaen

06-03-2008 22:25:56

Yep. Use a Character for that sort of thing, and use an if/else if block for left/right or up/down movements.