I will show the pieces of my code related to it.
This is called by the IEventReceiver inherited class everytime in the main loop:
Code: Select all
if(IsKeyDown(KEY_KEY_W))
{
vector3df oldrot = mCamera->getRotation();
mPlayer->walk(1);
mCamera->updateAbsolutePosition();
mCamera->setRotation(oldrot);
}
else if(IsKeyDown(KEY_KEY_D))
{
vector3df oldrot = mCamera->getRotation();
mPlayer->walk(2);
mCamera->updateAbsolutePosition();
mCamera->setRotation(oldrot);
}
else if(IsKeyDown(KEY_KEY_A))
{
vector3df oldrot = mCamera->getRotation();
mPlayer->walk(3);
mCamera->updateAbsolutePosition();
mCamera->setRotation(oldrot);
}
Code: Select all
mCamera = mSceneManager->addCameraSceneNode(mPlayer->getNode());
mCamera->bindTargetAndRotation(true);
Code: Select all
void Creature::walk(int dir)
{
vector3df oldpos = mNode->getPosition();
if(dir == 1)
mNode->setPosition(vector3df(oldpos.X, oldpos.Y, oldpos.Z + 1.0f));
else if(dir == 2)
mNode->setPosition(vector3df(oldpos.X + 1.0f, oldpos.Y, oldpos.Z));
else if(dir == 3)
mNode->setPosition(vector3df(oldpos.X - 1.0f, oldpos.Y, oldpos.Z));
}