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 / matrix / object collision

Author
Message
husky
21
Years of Service
User Offline
Joined: 13th Nov 2003
Location:
Posted: 5th Dec 2003 21:18
I'm an ADA/C++ teacher trying to learn darkbasic(so I can teach it to students next year), specifically object collision with a textured matrix. Darkbasic has the built in collision functions but I cannot get them to work. Can someone show me a sample of an object and matrix collision code??
Clarks
21
Years of Service
User Offline
Joined: 30th Oct 2003
Location: BALTIMORE,MARYLAND
Posted: 6th Dec 2003 00:42 Edited at: 6th Dec 2003 09:57
hey husky whats up
let me give a simple explanation
DarkBasic built in collision system is basically made to detect collisions with objects not matrixes. To detect a collision with a matrix first you must find the height of the matrix. For doing that theres a special function call (get ground heigt(matrixnumber,x,y))
look up the function in DB built in help to get full explanation.
Heres an example

`setup
sync on
sync rate 30
backdrop on
`make matrix for testing
make matrix 1,5000,5000,20,20
`make object for testing
make object sphere 1,10
`make variables for gravity and boost
gravity#=1.0
boost#=2.0

`main loop
do
`define object position and angle
px#=object position x(1)
pz#=object position z(1)
py#=object position y(1)
ay#=object angle y(1)
`get ground height function
matheight#=get ground height(1,px#,pz#)
`add gravity to pull object down
py#=py#-gravity#
`add some boost to move object up
if upkey()=1
py#=py#+boost#
endif
`heres where collison is detected
if py#<=matheight#
py#=matheight#
endif
`position object at new positions
position object 1,px#,py#,pz#
`create new camera positions
cx#=newxvalue(px#,ay#-180,20)
cz#=newzvalue(pz#,ay#-180,20)
`position camera at new position
position camera cx#,py#,cz#
`point camera at object
point camera px#,py#,pz#
`print positions to screen
set cursor 0,0
print "px#",px#
print "py#",py#
print "pz#",pz#
print "ay#",ay#
print "matheight#",matheight#
print "cx#",cx#
print "cz#",cz#
`update screen
sync
loop

`that should give an idea
Clarks
21
Years of Service
User Offline
Joined: 30th Oct 2003
Location: BALTIMORE,MARYLAND
Posted: 6th Dec 2003 00:45 Edited at: 6th Dec 2003 09:58
thanks darwin i didn't see it
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 6th Dec 2003 03:28
there is a edit button under you name and avatar and all that spaz

=<=Pudgie Wars=>=
Game engine: 20% = Models: 25% = Textures: 1% = Sounds/Music: 0% = www.geocities.com/bigapple_entertainment
husky
21
Years of Service
User Offline
Joined: 13th Nov 2003
Location:
Posted: 9th Dec 2003 20:40
Thanks for the info CLARKS. I tried it; it worked. I edited it for a lesson. Life is good. Now I'm working on making an object follow "the ground" with correct orientation. That doesn't seem easy.
Sean
Clarks
21
Years of Service
User Offline
Joined: 30th Oct 2003
Location: BALTIMORE,MARYLAND
Posted: 13th Dec 2003 01:39
What exactly do you mean with correct orientation.
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 14th Dec 2003 22:02
do you mean a car that all 4 tires stay on the ground? if so you glue a cube to each point on the (in this case) the car that you want to touch the ground. you then set each of those boxes to get matrix height() thingy. if you dont understand, just tell me and i'll try a little harder

Login to post a reply

Server time is: 2025-05-22 01:43:26
Your offset time is: 2025-05-22 01:43:26