Page 1 of 1

Keyboard Input - Smooth And Multiple keypress

Posted: Sun Jan 27, 2008 12:07 am
by ktyrer496
hi,

Im trying to make a ship move, and i need it to move smoothly, but now it move one bit at a time and looks really silly and bad, like a jerking motion. also how can i make it so i can press more than one key at a time so that the ship can move diagnally rather than just left then up etc..

my code is as follows:

class MyEventReceiver : public IEventReceiver
{
public:
//============================================CONTROLS================================================
virtual bool OnEvent(SEvent event)
{
if (event.KeyInput.Key == KEY_KEY_A)
{
core::vector3df v = Munch->getPosition();
v.X += -2.0f;
Munch->setPosition(v);
}
return true;
}
};
//=============================================CONTROLS END=============================================

Any help would be appreciated

regards

Posted: Sun Jan 27, 2008 2:40 am
by vitek
Search for bool keys, or click one of the links below...

The gist of it is that you just capture the key states in the event receiver. When a key is pressed down you set a flag, and when it is released, you clear the flag. Then, in the game loop, you check the state of the keys and do something based on their status.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=25813
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=17033
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=19657
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=25517

Travis

Posted: Sun Jan 27, 2008 12:00 pm
by rogerborg
If you download the latest SVN version, example 04.Movement has been updated to demonstrate storing key states.

Posted: Sun Jan 27, 2008 10:38 pm
by vitek
Yup. The first link in that list is to the patch you posted last week.

Travis