how can I create a crosshair for a FPS? also, how do I 'aim' the weapon so the particles/bullets come from the nozzel?
Where do I spawn collision rays from for damage?
FPS crosshair
Crosshair can be done by adding an IGUIImage or by driver->draw2DImage() in the centre of the screen.
Shooting from the nozel of the gun is simple done by changing the shooting code to shoot from the end of the gun instead of the centre of the screen; end of nozel = camera position + offset.
Not sure what you mean by the last question!
Shooting from the nozel of the gun is simple done by changing the shooting code to shoot from the end of the gun instead of the centre of the screen; end of nozel = camera position + offset.
Not sure what you mean by the last question!
I had some problems with this in my game.... I came up with an imperfect but sufficient solution i reckon.
With the original shooting code it shoots from the cameras position along the cameras view line. So to get it to shoot from the gun you move it to shoot from the gun nozel instead as mentioned previously.
What i then tried to do was to cast a line to find out where it should shoot to according to the crosshair, as otherwise it shoots towards a point far in front of the camera which isnt going to necessarily be the centre of the crosshair, though it will be close, but could look a bit ugly and innacurate. Unfortunately that method didn't work out for me and i didn't want to spend hours and days trying to get it working, it was behaving very strangely!
So i stuck with the initial target point of a point far in front of the cameras position, i did do some smasll offsetting of some sort to try and get it a bit closer to the centre of the camera though, but i forget where that offsetting was done heh!
With the original shooting code it shoots from the cameras position along the cameras view line. So to get it to shoot from the gun you move it to shoot from the gun nozel instead as mentioned previously.
What i then tried to do was to cast a line to find out where it should shoot to according to the crosshair, as otherwise it shoots towards a point far in front of the camera which isnt going to necessarily be the centre of the crosshair, though it will be close, but could look a bit ugly and innacurate. Unfortunately that method didn't work out for me and i didn't want to spend hours and days trying to get it working, it was behaving very strangely!
So i stuck with the initial target point of a point far in front of the cameras position, i did do some smasll offsetting of some sort to try and get it a bit closer to the centre of the camera though, but i forget where that offsetting was done heh!
I have made my own target like this:
It´s not what you are asking, but it has worked very well on me.
Code: Select all
float accuracy = 2.0f;
// more definitions....
// and the code
if(running)
accuracy += 0.5f;
else
accuracy -= 0.2f;
if(accuracy < 2.0f) accuracy = 2.0f;
if(accuracy > 20.0f) accuracy = 20.0f;
if(shooting)
{
float value = random(0.0f, accuracy); // get the random value between center of the targer and the border of the target
float randAngle = random(0.0f, 360.0f); // random angle
position2d<s32> pos(int(cos(randAngle)*value), int(sin(randAngle)*value));
ISceneNode* node = smgr->getSceneCollisionManager()->getSceneNodeFromScreenCoordinatesBB(pos);
// then check that the selected node is an enemy...
}
// other code...
int acc = int(accuracy);
pDriver->draw2DLine(position2d<s32>(512+acc,384), position2d<s32>(512+acc+10,384), SColor(255,0,0)); // right
pDriver->draw2DLine(position2d<s32>(512-acc,384), position2d<s32>(512-acc-10,384), SColor(255,0,0)); // left
pDriver->draw2DLine(position2d<s32>(512,384+acc), position2d<s32>(512,384+acc+10), SColor(255,0,0)); // down
pDriver->draw2DLine(position2d<s32>(512,384-acc), position2d<s32>(512,384-acc-10), SColor(255,0,0)); // up
Dattebayo!!