Well, in that code shown you only create one dwarf... so maybe check elsewhere that you are not creating two instances of game_entity, or calling init_entity twice... or that game_weapon is not using the wrong model...
You should walk through the flow of the code in your mind and it should be obvious where you are going wrong...
About key movement, I've commented in the code:
Code: Select all
void game_entity::KeyboardEvent(game_manager* entity_game_manager)
{
// this will be initialised with a default position of {0,0,0}
vector3df pos;
if(entity_game_manager->getKey(KEY_KEY_W))
{
// You now subtract 2 from the Z component, giving a position of {0,0,-2}
pos.Z = pos.Z - 2;
// So what you are actually doing is setting the position to
// {0,0,-2} each key press.
// Obviously you don't want to do that, you want to add 2 to the
// *current* position
entity_node->setPosition(pos);
entity_node->updateAbsolutePosition();
}
else if(entity_game_manager->getKey(KEY_KEY_S))
{
pos.Z = pos.Z + 2;
this->get_entity_node()->setPosition(pos);
entity_node->updateAbsolutePosition();
}
}
so a version that might work:
Code: Select all
void game_entity::KeyboardEvent(game_manager* entity_game_manager)
{
// Now we start with the *current* position of the entity node
// So when 2 is added to it below it has actually moved relative
// to its last position
vector3df pos = entity_node->getPosition();
if(entity_game_manager->getKey(KEY_KEY_W))
{
pos.Z = pos.Z - 2;
entity_node->setPosition(pos);
entity_node->updateAbsolutePosition();
}
else if(entity_game_manager->getKey(KEY_KEY_S))
{
pos.Z = pos.Z + 2;
this->get_entity_node()->setPosition(pos);
entity_node->updateAbsolutePosition();
}
}
But still, what you have here will only move your node in the Z axis, and also not relative to the direction the camera is looking, and will only move a single step each time you press a key. If you search the forum I am sure there are examples of how to do better movement... (or look in the source for how the irrlicht FPS camera works..)
also remember you should delete everything created with new...
you might want a destroy_entity method where you delete weapons[0];
and you might also want a good book on C++