OK, I have a 3D gun that is the child of the Camera1 node. I want to make it so when the gun comes close to a wall, it will rotate, so it doesn't
1) Go thru the wall, or
2) Using magic, always appear on top of the environment (This is a problem with many FPSs like MOH, Call of Duty, etc.).
So, would I make it so when it collides with the wall, it will cause some kind of event or what?
Wall & Gun
so it doesn't
2) Using magic, always appear on top of the environment
Supposedly you can set it as the first thing to be rendered before the scene manager draws all.
What you could do is a very simple collision detection; it could be as basic as a bounding box. If your gun collides with something -other than the camera or your player model then youd load a separate animation that lifts the gun's nozzle. If the gun is brought inside the bounding box of the camera/player, it shouldn't go through wall I guess.
common proffessional solutions to this are as follows:
1) dont deal with it
2) do a short ray cast from the camera, if an object intersects it, push the gun object backwards so that it does not pierce the wall (however, this is a client-side only fix, on multiplayer games the gun still goes thru the wall when viewed by others)
another solution which is much discussed but not implemented is called "iron sights" and basically means that rather than having a vector based on the camera that the projectile fire thru, the vector comes directly from the gun model's position. This means you need to create animations that put the gun in various positions that let the user fire in a realistic manner. Because you're already going to this length, its easier to coordinate model animation with wall collision-- easier, but still not done, even call of duty and some other games that make heavy use of iron sights do not resolve collision intelligently
1) dont deal with it
2) do a short ray cast from the camera, if an object intersects it, push the gun object backwards so that it does not pierce the wall (however, this is a client-side only fix, on multiplayer games the gun still goes thru the wall when viewed by others)
another solution which is much discussed but not implemented is called "iron sights" and basically means that rather than having a vector based on the camera that the projectile fire thru, the vector comes directly from the gun model's position. This means you need to create animations that put the gun in various positions that let the user fire in a realistic manner. Because you're already going to this length, its easier to coordinate model animation with wall collision-- easier, but still not done, even call of duty and some other games that make heavy use of iron sights do not resolve collision intelligently
a screen cap is worth 0x100000 DWORDS
no, i never tried the code, it was just a suggestion (i dont no if the guy got it working or not)
so, u mean like Metal Gear Solid3?
u also could simply rotate the gun to a preset rotation if its colliding with the level. u could just make a line3d going from the hand to its nozzle, where if theres a collision then its rotation is set at the preset amount, probably 90 along the x or y.
so, u mean like Metal Gear Solid3?
u also could simply rotate the gun to a preset rotation if its colliding with the level. u could just make a line3d going from the hand to its nozzle, where if theres a collision then its rotation is set at the preset amount, probably 90 along the x or y.
Ok, how would I set up a collision event? (As you can see, I'm a SuperNooB). So far, my event receiver looks like:
Code: Select all
class EventR1 : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* guienv = deviceIrr->getGUIEnvironment();
switch (event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
if (id == 0000000004)
{
if (globalswitch == 0)
{
mciSendString("stop media/mid1.mid",NULL,0,NULL);
}
}
if (id == 0000000003)
{
if (globalswitch == 0)
{
IGUIWindow *window1 = guienv->addWindow(rect<s32>(cnt+200,cnt+250,cnt+400,cnt+400),false,L"HELP");
guienv->addStaticText(L"\n\nThis software is based in part on the work of the Independent JPEG Group.\n\nProgrammer........\nSpecial Thanks....\nSpecial Thanks....",rect<s32>(20,25,180,130),1,1,window1);
}
}
if (id == 0000000002)
{
if (globalswitch == 0)
{
IGUIElement* root1 = guienv->getRootGUIElement();
IGUIElement* btd1 = root1->getElementFromId(0000000002,true);
btd1->remove();
IGUIElement* root2 = guienv->getRootGUIElement();
IGUIElement* btd2 = root1->getElementFromId(0000000001,true);
btd2->remove();
IGUIElement* root3 = guienv->getRootGUIElement();
IGUIElement* btd3 = root3->getElementFromId(0000000003,true);
btd3->remove();
IGUIElement* root4 = guienv->getRootGUIElement();
IGUIElement* btd4 = root4->getElementFromId(0000000004,true);
btd4->remove();
mciSendString("stop media/mid1.mid",NULL,0,NULL);
mciSendString("play media/mid2.mid",NULL,0,NULL);
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
globalswitch = 1;
}
}
if (id == 0000000001)
{
if (globalswitch == 0)
{
deviceIrr->closeDevice();
return true;
}
}
break;
}
}
return false;
}
};
just have a function where u plug in ur gun node
Code: Select all
GunCollide(ISceneNode* gun) {
line3d<f32> line;
line.start=gun->getPosition();
line.end=vector3df(5*sin(gun->getRotation.Y),5*sin(gun->getRotation.X),5*cos(gun->getRotation.Y)); //5 is the length of the handle to nozzle on the gun
triangle3d<f32> tri;
vector3df pos;
if(smgr->getSceneCollisionManager->getCollisionPoint(line,sel,tri,pos)) {
gun->setRotation(vector3df(90,0,0));
} //sel is ur lvl selector, covered in the example .7 of irrlicht
}
//as long as ur gun is a child of ur camera, the gun will always be set at 90 along the x axis, and will realign with the camera if there is no collison