I'm using Microsoft Visual C++, I was wondering if anyone had a simple demo showing how to use keyboard control. I tried the code suggested in the forum and it works but it does not move smoothly. When you hold a key down, the object moves, then stops, then moves again smoothly. It's just like when your typing and you hold a key down, it prints one letter, stops, and if you continue holding the key down it prints the same letter many times quikly.
Before I invest months learning how to use this 3D engine, I need to know that it can handle keyboard movement properly. Below is the code I'm using to move a block up and down using the Q and A keys:
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
//definition
bool keys[irr::KEY_KEY_CODES_COUNT] ;
//initialization
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
//onEvent
if(event.EventType == irr::EET_KEY_INPUT_EVENT){
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
//Using it
core::vector3df v = node->getPosition();
if(keys[irr::KEY_KEY_Q]) v.Y += 1;
if(keys[irr::KEY_KEY_A]) v.Y -= 1;
node->setPosition(v);
return true;
}
return false;
}
};
I really need to know if this problem can be fixed, any help would be appreciated.
New guy needs help
The problem that you are hitting isn't a problem with the engine, it's the timing for your events.
There are several posts on doing smooth movement.
It involves assigning a direction when the key is pressed and then updating the object every frame, not on the keypress event.
If you do it on the keypress event, your bound to get strange results, like.
Move
Pause
-Wait-
(typematic kicks in)
Move
Pause
Move
Pause
Due to the typematic rate you have set in your OS.
On event:
If keypress = forward_key
set direction = forward;
Each Render:
If direction = foward
move object forward
There are several posts on doing smooth movement.
It involves assigning a direction when the key is pressed and then updating the object every frame, not on the keypress event.
If you do it on the keypress event, your bound to get strange results, like.
Move
Pause
-Wait-
(typematic kicks in)
Move
Pause
Move
Pause
Due to the typematic rate you have set in your OS.
On event:
If keypress = forward_key
set direction = forward;
Each Render:
If direction = foward
move object forward
Crud, how do I do this again?
IT WORKS!!
saigumi, Thanks, I can now control objects with the keyboard smoothly.
Manakel, I'll try that soon, right now I have one object on the screen so the frame rate never really changes.
I have another question you guys might be able to help me with; Do I have to make the environment with a level editor program or can I create the environment with a regular model editor like Milkshape 3D? I'm confortable using Milkshape and I'm sure I could build a level with it. But I need to know if it will work the same for collision detection and would there be a differance in speed?
Manakel, I'll try that soon, right now I have one object on the screen so the frame rate never really changes.
I have another question you guys might be able to help me with; Do I have to make the environment with a level editor program or can I create the environment with a regular model editor like Milkshape 3D? I'm confortable using Milkshape and I'm sure I could build a level with it. But I need to know if it will work the same for collision detection and would there be a differance in speed?