Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / how do i fire a bullet from a gun

Author
Message
bobbyd
16
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 8th Mar 2009 17:36
how do i make a bullet fire from a gun
thanks for any help
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 8th Mar 2009 17:42
3d or 2d?
bobbyd
16
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 8th Mar 2009 17:43
3d
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 8th Mar 2009 17:49
one more thing, is it an actual bullet shape or just a sphere?
bobbyd
16
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 8th Mar 2009 17:50
just a sphere
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 8th Mar 2009 17:56 Edited at: 8th Mar 2009 17:57
dangit i was onto an idea but now im confused, i was guna try and use basically the same trig used in the clock program to find the x,y, and z changes for the next position of the bullet, but now im lost. wait for BN2 or some1 else from DarkNOOBS to post, theyll know
bobbyd
16
Years of Service
User Offline
Joined: 17th Jan 2009
Location:
Posted: 8th Mar 2009 17:58
ok thanks anyway
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Mar 2009 20:05
There's no real point in having an object for the bullet, because it'll move so fast you wont even see it (unless you have some matrixy thing going on) and certainly not a sphere that has loads of polys.

What you want is to take the angle of the gun when it's discharged and cast a line out at that angle, I think sparky's DLL has some ray-casting thing that does this but you can use newx() and newy() and newz(); you use them by giving the current position, the angle you want to move in and how far you want to move and the functions will work out the new points for you. Look them up in your help file.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 8th Mar 2009 20:53
o that would work to, i was trying to use the trig from the clock program, i never even thot of that
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Mar 2009 21:19
Quote: "o that would work to, i was trying to use the trig from the clock program, i never even thot of that "

You're right, New x/y/z use trig too.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 8th Mar 2009 23:02
Check out the Binary Moon tutorials: they have something that might help:

http://developer.thegamecreators.com/?f=t02/bm_tutorial_index

~QJ
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 02:29
Trig may not be necessary. Position the bullet at the gun's/camera's position, set the bullet to the orientation of the gun, camera, or character and then just move the bullet a certain distance each iteration if you want a physical bullet that you can see. Or, again, place an invisible plain at the camera, gun, or character's position, set the orientation of the plain to the gun camera, etc, move the plain to the maximum range of the weapon, then get the final coordinates of the plain for ray casting. Add random values to the final position to affect accuracy.

Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 9th Mar 2009 02:50
nice latch, but i try 2 avoid move object cuz it doesnt always move it the way you expect it to
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 03:48
I've never run into that. Do you have an example? Here's a variation of a camera following an object using MOVE for both. The bullet principal would be similar. One thing I forgot to note is in order to set an object to the camera orientation properly, use SET OBJECT ROTATION ZYX ahead of time on the object or the rotations will be incorrect:



Enjoy your day.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 9th Mar 2009 04:56
it was in a model i made a while back, it was a sniper (gun, not guy) that move moved it right instead of forward
Flyin Mushroom
17
Years of Service
User Offline
Joined: 12th Jun 2007
Location: Arkansas
Posted: 9th Mar 2009 05:44 Edited at: 9th Mar 2009 05:46
If I did this Forum Post Right on that code part, maybe you can get a idea on shooting bullets. It is a stick gun (rectangular box) shooting round spheres like a fully automatic machine gun. It has 90 bullet capacity before it reloads.

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 08:08
@Flyin Mushroom
Good job! There was a 'reflection' effect where there were bullets above and below the matrix.

Quote: "it was in a model i made a while back, it was a sniper (gun, not guy) that move moved it right instead of forward"


Oh, I see. Could be a simple case of the model orientation. When models are imported from 3d programs, often the model is facing a direction on a different axis than in DBC. Like maybe your model was pointing to the left (-X relative axis) and forward in DBC is into the monitor(+Z relative axis). So when you use MOVE, it moves the object on it's relative Z axis which would look sideways in relation to the models orientation. There are a couple of fixes for that. A quick fix is after loading it, rotate it to the correct orientation, then use FIX OBJECT PIVOT <obj>.

Enjoy your day.
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 24th Mar 2009 08:57
Thanks FlyinMushroom - this has helped me also!
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 25th Mar 2009 10:17
..at least I thought it did but cant seem to engineer it to work for me. It tried to backsolve to get the gun position based on the camera position in my game but no joy. Is anyone able to see anything obviously wrong with the code below (the gun doesnt appear anywhere at all - and its based it on the simple box gun for the time being)? The first chunk of code specifies the camera position, the second chunk tries to rejig the _weapon_control subroutine from the above code snippet. at this stage, I'm only interested in getting the gun to appear a short distance in front of the camera as per the box gun.



Rem Camera code
gridunitsize#=(landsize*2)/25.0
shx#=shx#+(x#-oldx#)
shz#=shz#+(z#-oldz#)
if shx#<0.0
shx#=shx#+gridunitsize#
shift matrix right 1
shtrackx=shtrackx+1
endif
if shx#>=gridunitsize#
shx#=shx#-gridunitsize#
shift matrix left 1
shtrackx=shtrackx-1
endif
if shz#<0.0
shz#=shz#+gridunitsize#
shift matrix down 1
shtrackz=shtrackz+1
endif
if shz#>=gridunitsize#
shz#=shz#-gridunitsize#
shift matrix up 1
shtrackz=shtrackz-1
endif

mx#=(x#-landsize)-shx#
mz#=(z#-landsize)-shz#
position matrix 1,mx#,0,mz#

rem Smooth control camera
cdx#=newxvalue(x#,a#,-50)
cdz#=newzvalue(z#,a#,-50)
cdy#=get ground height(1,cx#-mx#,cz#-mz#)+50
if cdy#<225 then cdy#=225
cx#=curvevalue(cdx#,cx#,10.0)
cy#=curvevalue(cdy#,cy#,10.0)
cz#=curvevalue(cdz#,cz#,10.0)
position camera cx#,(get ground height(1,x#-mx#,z#-mz#))+90,cz#
camypos#=(get ground height(1,x#-mx#,z#-mz#))+ChasGPos#
point camera x#,camypos#,z#
Rem End Camera code

Rem _Weapon_control rejigged
Rem position Gun in front of camera
cxa#=camera angle x()
cya#=camera angle y()
gga#=wrapvalue((cya#-20))
ggx#=newxvalue(x#,gga#,-1)
ggz#=newzvalue(z#,gga#,-1)
gpdx#=newxvalue(ggx#,wrapvalue((cya#-20)),10)
` gpdy#=y#-(sin(cxa#)*10)
gpdy#=camypos#-(30+sin(cxa#)*10)
gpdz#=newzvalue(ggz#,gga#,10)
gpx#(0)=curvevalue(gpdx#,gpx#(0),gunlag#)
gpy#(0)=curvevalue(gpdy#,gpy#(0),gunlag#)
gpz#(0)=curvevalue(gpdz#,gpz#(0),gunlag#)

position object 2,gpx#(0),gpy#(0)+25,gpz#(0)
xrotate object 2,wrapvalue(0-cxa#)
yrotate object 2,wrapvalue(cya#+180)
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 25th Mar 2009 11:22
You could use lock object on (I think thats the command). That makes it use the camera as its origin, rather than the global origin (coordinate 0,0,0). It takes some work positioning the object correctly, but once you do, it shouldn't give you any trouble.

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 25th Mar 2009 12:33
Thanks, I already tried that. I want to use Flyin Mushrooms idea because I can then use the position of the gun to fire the bullet.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 25th Mar 2009 16:33
not sure wat the problem is exactly but one trick you could use to make the gun appear in front of the camera would be to do something like this:



then in ur main loop do something like this to reposition the hidden sphere limb at the camera and rotate it



i made this off memory so dont be surprised if i messed something up
Hangar18
18
Years of Service
User Offline
Joined: 13th Mar 2007
Location:
Posted: 26th Mar 2009 03:45
Ah yes thanks! I'd forgotten about set object to camera orientation.
That1Smart Guy
16
Years of Service
User Offline
Joined: 26th Feb 2009
Location: Somewhere...... yep
Posted: 26th Mar 2009 03:48
np, quite useful in FPS games, it did work right?

Login to post a reply

Server time is: 2025-05-16 20:50:26
Your offset time is: 2025-05-16 20:50:26