Ok lets get into it, Outside main.cpp (Globals, or In a Header file, Classes etc..)
Code: Select all
int speed; // HOW FAST YOU GO
ICameraSceneNode* camera;
vector3df playerpos; // PLAYERS POSITION
vector3df playerrot; // PLAYERS ROTATION
bool keys[irr::KEY_KEY_CODES_COUNT]; // THE KEYS!!!
virtual bool OnEvent(const SEvent& event)
{
if(event.EventType == irr::EET_KEY_INPUT_EVENT)
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
return false;
}
In Main.cpp
Code: Select all
keys[KEY_ESCAPE] = false;
keys[KEY_KEY_W] = false;
keys[KEY_KEY_S] = false;
keys[KEY_KEY_A] = false;
keys[KEY_KEY_D] = false;
Code: Select all
if(keys[KEY_ESCAPE])
{
device->closeDevice();
keys[KEY_ESCAPE] = false;
}
if (keys[KEY_KEY_W])
{
playerpos.X += speed * cos((playerrot.Y) * 3.14/ 180);
playerpos.Z -= speed * sin((playerrot.Y) * 3.14/180);
keys[KEY_KEY_W] = false;
}
if (keys[KEY_KEY_S])
{
playerpos.X -= speed * cos((playerrot.Y) * 3.14/180);
playerpos.Z += speed * sin((playerrot.Y) * 3.14/180);
keys[KEY_KEY_S] = false;
}
if (keys[KEY_KEY_A])
{
playerrot.Y -= 3;
keys[KEY_KEY_A] = false;
}
if (keys[KEY_KEY_D])
{
playerrot.Y += 3;
keys[KEY_KEY_D] = false;
}
sonic_node->setPosition(playerpos);
sonic_node->setRotation(vector3df(playerrot.X, (playerrot.Y-90), playerrot.Z));
sonic_node->addChild(camera);
vector3df cameratarg = playerpos; // Look at this I declare the variable every time in the loop!
cameratarg.Y += 200; // Needs to be Tinkered With
camera->setTarget(cameratarg);
(I am wearing anti-flame gear thx)