Help
![Sad :(](./images/smilies/icon_sad.gif)
Nooo no no, that's what I'm wanting. What I'm trying to do is make the weapon aim just a bit downward instead of straight forward from the head/camera's point of view. But it seems that I can only roll the weapon, or rotate it to the left or right. Up and down just doesn't seem to work.shadowslair wrote:If I`m not mistaken, when using a child all its transformations (position, rotation, scale) are relative to its parent`s, which in 99% is what we need, but probably this is causing you trouble.
Code: Select all
// Init variables
IAnimatedMesh* mesh = smgr->getMesh("stupidgun (2).3ds");
IAnimatedMesh* mesh2 = smgr->getMesh("cube.3ds");
ICameraSceneNode* cam = smgr->addCameraSceneNode(0, vector3df(0,0,-20), vector3df(0,0,0));
IAnimatedMeshSceneNode* weapon = smgr->addAnimatedMeshSceneNode(mesh);
IAnimatedMeshSceneNode* playerHead = smgr->addAnimatedMeshSceneNode(mesh2);
IAnimatedMeshSceneNode* camTarget = smgr->addAnimatedMeshSceneNode(mesh2);
// Set parents
cam->setParent(playerHead);
weapon->setParent(playerHead);
camTarget->setParent(playerHead);
// Set some other stuff
if (weapon) weapon->setMaterialTexture(0, driver->getTexture("derp.bmp"));
playerHead->setPosition(vector3df(10,10,10));
playerHead->setRotation(vector3df(0,0,0));
camTarget->setPosition(vector3df(0,0,100));
cam->setPosition(vector3df(0,0,5));
cam->setTarget(camTarget->getAbsolutePosition());
weapon->setPosition(vector3df(6,-3,20));
weapon->setRotation(vector3df(0,-90,0)); // <--- ***This is the problem***
smgr->addLightSceneNode(0, vector3df(0,0,0), SColor(0,1,0,0), 800);
float mouse_sens = 0.1f;
// Game loop *****
while(device->run())
{
vector3df position = playerHead->getPosition();
vector3df rotation = playerHead->getRotation();
if (keyboard.IsKeyDown(KEY_KEY_W)) position.Z += 0.02f;
if (keyboard.IsKeyDown(KEY_KEY_S)) position.Z -= 0.02f;
if (keyboard.IsKeyDown(KEY_KEY_D)) position.X += 0.02f;
if (keyboard.IsKeyDown(KEY_KEY_A)) position.X -= 0.02f;
if (keyboard.IsKeyDown(KEY_UP)) rotation.X -= mouse_sens;
if (keyboard.IsKeyDown(KEY_DOWN)) rotation.X += mouse_sens;
if (keyboard.IsKeyDown(KEY_RIGHT)) rotation.Y += mouse_sens;
if (keyboard.IsKeyDown(KEY_LEFT)) rotation.Y -= mouse_sens;
if (rotation.X < -89.9f) rotation.X = -89.9f;
if (rotation.X > 89.9f) rotation.X = 89.9f;
playerHead->setPosition(position);
playerHead->setRotation(rotation);
cam->setTarget(camTarget->getAbsolutePosition());
driver->beginScene(true, true, SColor(255,140,255,255));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}