I am making a shoot function with my game and my dad ( being the geinous programmer that he is ) suggested that i should generate an imaginary line from the gun to whatever it's aiming at and then, if the user clicks then put a bulet hole at what its aiming at.
I am using vc++
i have windows XP pro sp3
and i am using The DarkDGK engine and library

any help would be good :)

Is it 2d/3d ???

If it is 2d then create a line factoring in the angle of the gun and other variables don't draw it on the screen, just keep track of the end point.

In the current frame if the user click on the FIRE button, before rendering the next frame load the texture of a bullet hole in the target area.

If its 3d, schedule another talk with dad.

This is me, just "shootin in the dark" :wink.

Hope i have helped.

Edit: You are using an engine, i gave you the logic i am sorry i have no experience in DARKDGK engine.

Edit2:I assumed that the bullet travels in a straight line, from the barrel to the destination and then you stop tracking the bullet.

if the barrel is held parallel to the ground then
target = (x,y,z+RANGE_OF_BULLET).
if FIRE BUTTTON IS PRESSED {
load bullet hole texture at target
}
else {
do nothing
}

render frame().

I am sorry, i cant help you with gun held at an angle. Refer some books like physics for game programmers (or the documentation of your game engine).

I have tried this before, i found the best approach is not to use actual bullet object. Just animate the gun firing and put an aimer in the middle of the screen. From here you could test if the aimer is pointing at anything and that the gun has fired, if so place a bullet hole on the object being shot at.

This article has been dead for over six months. Start a new discussion instead.