FPS crosshair

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

FPS crosshair

Post by JPulham »

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?
pushpork
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

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!
Image Image Image
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Post by JPulham »

If I have a crosshair in the center of the screen how do I point the gun at the 'target', so If i plot a visible ray from the gun nozzel to the target it ends at the crosshair?
pushpork
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

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!
Image Image Image
Dibalo
Posts: 30
Joined: Sat Aug 12, 2006 2:31 pm
Location: Finland
Contact:

Post by Dibalo »

I have made my own target like this:

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
It´s not what you are asking, but it has worked very well on me.
Dattebayo!!
Post Reply