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 / collision detection

Author
Message
GALACTUS
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 1st Jul 2004 03:50
I was looking at a tutorial in here and I don't see how this determines a collision.

if Sqrt((mX# - bX#)^2 + (mY#+25 - bY#)^2 + (mZ# - bZ#)^2) <20
text 240,220 ,"hit hit hit hit hit hit hit hit"
BulletLife = 0
Endif

They had nothing for mX, mY, or mZ

Please help

Thanks

Aaron

Hey!!
GALACTUS
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 1st Jul 2004 03:52
Here's the whole program

Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000

Fog on
Fog distance 4000
Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)

Rem make matrix
Make matrix 1,50000,50000,20,20

Rem texture matrix
Load image "C:\Aaronsmisc1\Source\grass09.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1

rem Make Gun
Make object cylinder 1,2
XRotate Object 1,90
Fix object pivot 1
Scale object 1,100,100,300
position object 1,0,-7,15
Lock object on 1

Rem Make bullet
Make Object Sphere 2,2
Hide Object 2

Load sound "C:\Aaronsmisc1\Source\crickets.wav",1
Loop sound 1

Load 3Dsound "C:\Aaronsmisc1\Source\fireball2.wav",2
MAKE OBJECT BOX 3, 44, 44, 44
position object 3,2000,0,1500



rem Randomize the matrix
randomize matrix 1,125
X#=5000
Z#=5000



Rem Main loop
Do

set cursor 0,0
print X#
print Y#
print Z#




OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = WrapValue(CameraAngleY#+MousemoveX()*0.2)
CameraAngleX# = WrapValue(CameraAngleX#+MousemoveY()*0.2)

Rem Control input for camera
If Upkey()=1
XTest# = Newxvalue(X#,CameraAngleY#,10)
ZTest# = Newzvalue(Z#,CameraAngleY#,10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif

If Downkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-180),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-180),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif

If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif

If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#+90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#+90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif

Rem Rotate camera
if CameraAngleX#>270
if CameraAngleX#-270 > 90 then CameraAngleX#=270
else
if CameraAngleX# > 90 and CameraAngleX#-270<270 then CameraAngleX#=90
endif



Yrotate camera CurveAngle(CameraAngleY#,OldCamAngleY#,24)
Xrotate camera CurveAngle(CameraAngleX#,OldCamAngleX#,24)

Y# = Get ground height(1,X#,Z#)
Position Camera X#,Y#+50,Z#


if Mouseclick()=1 and BulletLife=0
Position object 2,X#,Y#+45,Z#
Set object to camera orientation 2
BulletLife =25
Show object 2
Loop sound 2
Endif

If BulletLife > 0
Dec BulletLife
Move object 2,20
bX#=Object position X(2)
bY#=Object position Y(2)
bZ#=Object position Z(2)
Position sound 2,bX#,bY#,bZ#
set cursor 10,10
if Sqrt((mX# - bX#)^2 + (mY#+25 - bY#)^2 + (mZ# - bZ#)^2) <20
text 240,220 ,"hit hit hit hit hit hit hit hit"
BulletLife = 0
Endif
if BulletLife = 0
Hide object 2
stop sound 2
Endif
Endif





Rem Position Listener
Position Listener X#,Y#+50,Z#
Rotate Listener 0,cameraAngleY#,0




Rem Refresh Screen
Sync
Loop



return

Hey!!
dj BlackDragon
21
Years of Service
User Offline
Joined: 23rd Sep 2003
Location: who knows
Posted: 1st Jul 2004 04:03 Edited at: 1st Jul 2004 04:14
could be that the positions were already calculated in the program before it called up the collision part of it.just a thought...
but the thing is did you try it out before you posted?



Current project:Quest for the Five Staffs of Draconia
GALACTUS
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 1st Jul 2004 05:04
Yeah,

Copy and try it yourself...The variables mX, Y, and Z have no logic

Hey!!
GALACTUS
20
Years of Service
User Offline
Joined: 24th Apr 2004
Location:
Posted: 1st Jul 2004 05:10
I should have done this..check out this tutorial link, which is a wonderful tut for newcomers like myself...except when you get to 3.6

http://developer.thegamecreators.com/?f=t01/3d_tutorial_index

Hey!!
dj BlackDragon
21
Years of Service
User Offline
Joined: 23rd Sep 2003
Location: who knows
Posted: 1st Jul 2004 07:18
ah what language and i tried it out before i posted and it worked like a charm.



Current project:Quest for the Five Staffs of Draconia
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 1st Jul 2004 11:29
i was wodering that my self when i tried to make collision in my own program but i couldnt figure it out

mulletman47@aol.com
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 2nd Jul 2004 02:52
Yeah, although the bullet it shown by the mouse click, it's not being detected against anything. Since the target seems to be the BOX made up near the top, add in the lines;
mX = 20000
my = 0
mz = 1500
(which matches the object move after the box is created.)

Good luck!
s.

Any truly great code should be indisguishable from magic.
Hop a long
20
Years of Service
User Offline
Joined: 12th May 2004
Location: The Code Dump
Posted: 3rd Jul 2004 11:44 Edited at: 3rd Jul 2004 11:50
There has been a lot of give and take in the posts so far and I'm not quite sure if DB has the answer he's looking for or not.
Quote: "I should have done this..check out this tutorial link, which is a wonderful tut for newcomers like myself...except when you get to 3.6
"

The code DB posted is from the Monster Hunt Tut but the example he has appears tobe incomplete. The loading of the Monster is left out. This is the target whose position is compared to the bullet.

You can see it is the last thing done before the main loop begins.

As far as understanding the mathhttp://www.nuclearpublishing.com/hosting/emperorbaal/

Login to post a reply

Server time is: 2024-11-26 23:24:10
Your offset time is: 2024-11-26 23:24:10