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.

Newcomers DBPro Corner / noob help !!

Author
Message
Justice
20
Years of Service
User Offline
Joined: 22nd Jun 2004
Location:
Posted: 3rd May 2009 22:39 Edited at: 3rd May 2009 23:49
Hi,

I have created a simple 3d world and i can move around fine and detect any collision i bump into.

I have a couple of small problems i was hoping someone could help me with.

1. I was trying to design a bob movement for my gun for when i move along but its not very realistic

2. When i fire my gun the bullets fire ok except when i turn my gun up or down and then the bullets still fire straight along.

3. when i try to detect if my bullets have hit anything, it detects that i have hit object 1 (the world object) straight away.


I havn't been programming long and any help would be great !!

I have enclosed my code , please help !!!!



Rem * World_Engine *
Rem * NGC Version 4.02 *

sync on
sync rate 60
autocam off
hide mouse
backdrop on
set camera range 10,30000

rem global array to hold the "hold status" of each key pressed
global dim KeyHold(256)
rem global array to hold the "hold status" of each key pressed
global dim LastKeyHold(256)
rem global array for bullets *
global dim xdir(5000,5)

global dim door(50)

gravity=1
mousesence=3

rem * load Nuclear Glory Extension commands (V4.02) *
#Constant type_ngc_ellip=1
#Constant type_ngc_mesh=2
#Constant ellip_2_ellip=1
#Constant ellip_2_POLY=2
#Constant resp_stick=1
#Constant resp_slide=2
#Constant resp_slide_no_slopes=6
#Constant resp_slide_no_grav=10
#Constant resp_slide_no_accel=18
#Constant resp_none=32
#Constant dyn_no_resp=1
#Constant dyn_resp=2
#Constant dyn_resp_lock=6
#Constant dyn_resp_lock_noturn=14
#Constant ncull_clock 0
#Constant ncull_coounter_clock 1
#Constant ncull_none 2

#constant player_obj=1
#constant world_obj=2

startcollisionpro(0,0,0)
startcollisiondebugpro()
SetOctreeBuildPRO(0)
rem * set up player wall collision detection *
setcollisionspro(player_obj,world_obj,ellip_2_poly,resp_slide_no_accel,dyn_no_resp)

rem * load 3D World *
load object "models/paulsworld.x",1
collisiontypepro(1,world_obj)
positionobjectpro(1,0,-200,0)

rem * load collision sphere *
make object sphere 2,50
positionobjectpro(2,-262,-151,-13)
collisiontypepro(2,player_obj)
setobjgravitypro(2,3)
a=object size x(2)
b=object size y(2)
c=object size z(2)
setobjradiuspro(2,a/2+22,b/2+25,c/2+15)
hide object 2

rem * load gun object *
global player=50
load object "models/gun.x",50
scaleobjectpro(50,75,75,75)
xrotateobjectpro(50,270)
position object 50, 0, 0, 10
fix object pivot 50
lock object on 50

Changedir = 0
bobspeed# = .5
WeaponLocX# = 0
WeaponLocY# = -20
WeaponLocZ# = 0

rem Setup main soft light
set ambient light 60

rem * create bullets *
bullets=20
bullet_count=20
bullet_obj=3999
gosub create_bullets

time=timer()
elapsed=0

rem * load game sound effects *

load sound "media/dampstep.wav",2
set sound volume 2,75

load sound "media/gunfire.wav",3

gosub gun_bob

do


rem Update input data
UpdateKeyHold()

rem * check for any keys pressed *
gosub key_mouse_control
rem * move bullets *
gosub move_bullets
rem * show text on screen *
gosub text_display

nx=object position x(2)
ny=object position y(2)
nz=object position z(2)
positionobjectpro(2,nx,ny,nz)
position camera 0,nx,ny+60,nz

runcollisionpro()

fastsync
loop

end

rem * check for mouse & key inputs *
key_mouse_control:
playermoved=0

rem * straf right & left *
if rightkey()=1
moveobjectrightpro(2,10)
playermoved=1
endif
if leftkey()=1
moveobjectleftpro(2,10)
playermoved=1
endif

rem * jump routine (space key) *
if keyhold(57)=1
nx=object position x(2)
ny=object position y(2)
nz=object position z(2)
ny=ny+10
positionobjectpro(2,nx,ny+2.5,nz)
endif

rem * control key fire *
if controlkey()=1 and bullet_count>0
elapsed=(timer()-t)/100
if elapsed>1
play sound 3
inc bullet_obj
xdir(bullet_obj,1)=object position x(2)
xdir(bullet_obj,2)=object position y(2)
xdir(bullet_obj,3)=object position z(2)
xdir(bullet_obj,4)=1
positionobjectpro(bullet_obj,xdir(bullet_obj,1),xdir(bullet_obj,2)+50,xdir(bullet_obj,3))
rem rotate object bullet_obj,anglez#,angley#-180,anglex#
rotate object bullet_obj,0,angley#-180,0
show object bullet_obj
dec bullet_count
if bullet_count<1
bullets=20
bullet_count=20
bullet_obj=3999
endif
t=timer()
endif
endif

rotate object 2,object angle x(2)+(mousemovey()/mousesence),object angle y(2)+(mousemovex()/mousesence),0
rotate object 2,object angle x(2)+(mousemovex()/mousesence),object angle y(2)+(mousemovex()/mousesence),0
if object angle x(2)>90 then xrotateobjectpro(2,90)
if object angle x(2)<-90 then xrotateobjectpro(2,-90)
cx=object angle x(2)
cy=object angle y(2)
cz=object angle z(2)
rotate camera cx,cy,cz
rotateobjectpro(2,cx,cy,cz)
anglex#=object angle x(2)
angley#=object angle y(2)
anglez#=object angle z(2)

if mouseclick()=1 or upkey()=1
xrotateobjectpro(2,0)
moveobjectpro(2,10)
xrotateobjectpro(2,cx)
playermoved = 1
endif

if mouseclick()=2 or downkey()=1
xrotateobjectpro(2,0)
moveobjectpro(2,-10)
xrotateobjectpro(2,cx)
playermoved = 1
endif

if playermoved = 1
gosub Gun_Bob
endif

return

rem * display any text on screen *
text_display:
text 10,10,"Pauls World - 3DyWorld Studio Demo"
text 10,40,"x = "+str$(object position x(2))
text 10,60,"y = "+str$(object position y(2))
text 10,80,"z = "+str$(object position z(2))
text 10,100,"angle y = "+str$(object angle y(2))
text 10,120,"Screen FPS = "+str$(screen fps())
return

rem * create bullets *
create_bullets:
for i=4000 to 4000+bullets
if object exist(i)=0
make object sphere i,10
hide object i
endif
next i
return

rem * move bullets *
move_bullets:
for i=4000 to 4000+bullets
if xdir(i,4)=1
if distance(i,2)<55
hide object i
else
show object i
endif
move object i,-10
rem * check if bullet has hit a wall *
hit=object collision(i,0)
if hit>0
text 100,180,"object "+str$(i)+" hit object "+str$(hit)
xdir(i,4)=0
hide object i
endif
endif
next i
return

rem * bob gun when walking *
Gun_Bob:
if sound playing(2)=0 then play sound 2
inc i#, bobspeed#
i# = wrapvalue(i#)
inc j#, bobspeed#
j# = wrapvalue(j#)
if j# >= 180 or j# >= 180
if Changedir = 0
Changedir = 1
bobspeed# = 0-bobspeed#
endif
else
Changedir = 0
endif
rem * move gun left & right *
rem bob_x# = cos(i#)*2
rem * move gun up & down *
bob_y# = sin(j#)*2
positionobjectpro(50,WeaponLocX#-bob_x#, WeaponLocY#-bob_y#+3, WeaponLocZ#)
return

Attachments

Login to view attachments
Gingerkid Jack
19
Years of Service
User Offline
Joined: 15th May 2005
Location: UK
Posted: 3rd May 2009 23:06 Edited at: 3rd May 2009 23:07
Put your code in a code box so its easy for people to reply. Also your going to get flamed for that title. Don't just write noob question. Write down a fitting title. Lol Im rambling.

Also for the bob why don't you just put it in the animation?

Jack

TheCleverGuyz
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 3rd May 2009 23:55 Edited at: 3rd May 2009 23:56
1. You could put it into the animation OR use CURVEVALUE (or cosine if you wanted to) to smooth out the bob.

2. When firing the bullets, you only rotate them on the Y axis. Try rotating them to the camera/gun's X angle as well.

3. If you use Nuclear Glory for your collision, you'd be best off using its commands for bullet collision as well. I don't use nuclear glory so I wouldn't know what to do, but perhaps the OBJECT COLLISION command has a nuclear glory counterpart?

<-- Spell based team dueling game!

Login to post a reply

Server time is: 2024-11-25 08:05:41
Your offset time is: 2024-11-25 08:05:41