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 / Collision Detection Problems

Author
Message
Jordash
22
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 21st Jan 2003 02:49
Hey first off thanks for reading this post I have been having problems with some collision detection in a game i am attempting to make. I'll show the the code then try and explain the problem. What i'm trying to do is make a model I drew move back and forth between two cubes it seems simple until i tried to do it, heres what I tried(note alot of this isn't exactly like my program but it's close enough note i also did all the sync stuff but not in this small code here):
rem i loaded and made my objects and positioned them
rem and put collision detection on
load object "whatever.x",1
position object 1,0,0,0
set object collision on 1

make object cube 2,10
position object 2,10,0,0
set object collision on 2

make object cube 3,10
position object 3,-10,0,0
set object collision on 3

rem i then made a variable which use i will explain later
patrol = 1

rem i then started the loop
do
rem
got positions of all the models
sqoX# = object position X(2)
sqoY# = object position Y(2)
sqoZ# = object position Z(2)
sqtX# = object position X(3)
sqtY# = object position Y(3)
sqtZ# = object position Z(3)
rem now i use the 'patrol' variable to know which square to rem move it to
if patrol = 1
point object 1,sqoX#,sqoY#,sqoZ#
move object 1,5
endif
if patrol = 2
point object 1,sqtX#,sqtY#,sqtZ#
move object 1,5
endif
rem now i do collision detection to change the
rem variable 'patrol'
if object collision(1,2)>0
patrol = 2
endif
if object collision(1,3)>0
patrol = 1
endif
loop

and their is my code and what i thought this would simply do was move my model from one square to the next in a continuous loop (in my game this is going to be a badguy patrolling from one point to another) but what happens is my models moves to the first square and the detects the collision when it hits and moves towards the other square but then when it hits that one it just stops, i've also noticed that the collision detection i put first is the only one it detects, and the second one nothing happens. I was wondering if anyone could help me with this, or have any better way to do the same thing. Thanks!
SonicBoom
22
Years of Service
User Offline
Joined: 26th Nov 2002
Location:
Posted: 22nd Jan 2003 11:58
This sounds very similar to something I did a while ago. My thought was, rather than use DB collision, which I think works on boxes, all you really want to do is find the distance between your Patroller's position and the Aim Point in question.

A simple but very usefull function would take care of this:
Function 3d_distance(ax#,ay#,az#,bx#,by#,bz#)
dist# = Sqrt((ax# - bx#)^2 + (ay# - b#)^2 + (az# - bz#)^2)
EndFunction dist#

Login to post a reply

Server time is: 2025-05-14 09:34:11
Your offset time is: 2025-05-14 09:34:11