Node Movement Hesitation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
MiddleTommy
Posts: 6
Joined: Tue Nov 21, 2006 6:13 pm

Node Movement Hesitation

Post by MiddleTommy »

In the tutorials there is a movement example where you move a ball up or down using the keyboard. My trouble is I have removed the
!event.KeyInput.PressedDown
from the "if" statement to allow the ball to keep moving if you hold down the key.
What happens is the ball moves pauses and then keeps moving.
1) How do I remove the pause?
2) Movement of the ball is jumpy after the pause because of the space the ball is moving at each loop. If i shorten the spaced moved, movement is smoother but alot slower. How do you move nodes with the keyboard with out having jittery movement of the node?

ie when you move the camera with the keyboard it is smooth without hesitation unlike node in movement example.
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

You may want to look at this post: http://irrlicht.sourceforge.net/phpBB2/ ... olean+keys

Or go to the bottom of http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=16772 you can find there my MyEventReceiver class which do what you seek for. At last I think so :)
MiddleTommy
Posts: 6
Joined: Tue Nov 21, 2006 6:13 pm

Post by MiddleTommy »

I dont see right away how this answers my question?
I was thinking it was some setting for reapeating character timespan or something. I will try the bool keys when I get home tonight (and your event handeler to see if it makes a difference).
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

the method you're using is for when someone types a key, this isn't what you want though. you need to move something each frame depending on whether the key is held down or not. that's how the keystate array helps you- do the movement each frame if they key is held down, not as each keypress event happens
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
MiddleTommy
Posts: 6
Joined: Tue Nov 21, 2006 6:13 pm

Post by MiddleTommy »

I got it now.
Just use the Event to set whether the key pressed or released
then handle the movement from the main game loop if the key is down

They should update the example to be like this.

Thanks all for your help :roll:

I have been programing for a while but am still getting used to game logic
MiddleTommy
Posts: 6
Joined: Tue Nov 21, 2006 6:13 pm

Post by MiddleTommy »

Just in case anyone is new and found this thread I will post the modified source for main.cpp from the modified movement example

Code: Select all

//Add variables for key down state 
bool skey_down = false;
bool wkey_down = false;
//also you could make these static members of the My event reciever and always have the current state of the key down where ever you have the object
class MyEventReceiver : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (node != 0 && event.EventType == irr::EET_KEY_INPUT_EVENT)
		{
			switch(event.KeyInput.Key)
			{
			case KEY_KEY_W:
				wkey_down = event.KeyInput.PressedDown;
				return true;
			case KEY_KEY_S:
				skey_down = event.KeyInput.PressedDown;
				return true;
			default:
				return false;
			}
			
		}

		return false;
	}
};
And then the changes to the game loop:

Code: Select all

//this code should be inside main function
//replace code for the device->run() loop
while(device->run())
	{
		driver->beginScene(true, true, video::SColor(255,113,113,133));

		smgr->drawAll(); // draw the 3d scene
		device->getGUIEnvironment()->drawAll(); // draw the gui environment (the logo)

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			wchar_t tmp[1024];
			swprintf(tmp, 1024, L"Movement Example - Irrlicht Engine [%ls] fps: %d", 
				driver->getName(), fps);

			device->setWindowCaption(tmp);
			lastFPS = fps;
		}
		if(wkey_down || skey_down)
		{
			core::vector3df v = node->getPosition();

			v.Y += wkey_down > skey_down ? 0.1f : wkey_down == skey_down ? 0 : -0.1f;// if both are true then dont move
			node->setPosition(v);
		}

	}
Post Reply