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

Author
Message
ronin
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location:
Posted: 20th Feb 2003 00:55
I am trying to detect a ball hitting a character, I know I could use math but since the ball is big I would like to make a reallistic collision detection. With the "object collision" function it works in most of cases but because the step and ball size sometimes it just pass through the target, I dont want to reduce the step neither the ball radius, so if anybody can bring some ideas...
arras
22
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 20th Feb 2003 16:27
You can divide your step in to the substeps, making sure that substep is smaller than ball diameter or object size. Then detect kolision for each substep, then go further in loop.

schematicaly it should look like:

do
.
.
.
.
for a=1 to 10
-move ball 5-
-detect collision for ball-
next a
.
.
.
loop

this would move ball 5 x 10 = 50 units, detecting collision afther each 5
if size of ball and object is bigger then 5, you are sure it detect collision correctly...

ronin
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location:
Posted: 20th Feb 2003 23:49
ah... thanx, I tried something similar when i first met this problem but the fact here is that making the divisions smaller enough to avoid missin a target finally make it slow down coz even for small steps this make DB make a lot of collsion dtection per frame and you really pay it at the end, but thanx anyway I will come over this solution once again ^^

Chiwawa
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Canada
Posted: 20th Feb 2003 23:56
but....try to do your own..collision cause DB collision ...are REALLY REALLY REALLY SLOW!!!

the box collision r the fastest one..but still REALLY slower than your own math..
ronin
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location:
Posted: 21st Feb 2003 01:22
but how can you make with just maths an accurate collision detection, like detecting when a character is hitted in the arm or in the head?

Chiwawa
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Canada
Posted: 21st Feb 2003 04:00
it should be ez...if you want it ez.... ok for the ZX collision ..i think you know how... and to know if the ball hit your caracter in the head or..arm ... you just get the Y collision......

but....it depend..of what you need exactly...and it depent of the animation of your caractere..cause if he is not animated...you just get your limb coordinate...and you check if the ball is in that aera.... for the limb coordinate..you use the "limb offset" command...or u get it directly in the ".X"...but y do u want to get the exact position of collistion??? ...answer that and maybe ill answer.... better than that...
Chiwawa
22
Years of Service
User Offline
Joined: 13th Oct 2002
Location: Canada
Posted: 21st Feb 2003 04:06
lol...i just get an idea..... u can user the "object in screen"...i dont know if when the object is hide by another..this function return 0...i hope..if yes..use that and some simple math..to know if the object is "in" the caractere.... should not be too hard..
trager
22
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 21st Feb 2003 10:29
I posted a coll tutorial in the snippets section I stopped writting it as no-one was interested but its still there.

Its a very simple set of demos demonstrating fast acurate collision in 2D but it can be turned to 3D.

This collision detection is made for objects moving super fast without using a loop.

Just a shame no-one was interested else I would have made it pixel perfect by now.
arras
22
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 21st Feb 2003 12:02
You can make fast detection and only if something is close enough, you make more precise detecting.

The simplest detection is ball one, you just detect if distance between ball and objects is smaller than size of ball+size of object (for object you take bigest size it have):

distance#=sqrt((x_ball#-x_object#)*(x_ball#-x_object#)+(y_ball#-y_object#)*(y_ball#-y_object#)+(z_ball#-z_object#)*(z_ball#-z_object#))

if distance#<ball_size#+object_size# then ---make more precize collision detection for these two ball and object--


similar if you move ball for 50 units each time and substep is 5:

distance#=sqrt((x_ball#-x_object#)*(x_ball#-x_object#)+(y_ball#-y_object#)*(y_ball#-y_object#)+(z_ball#-z_object#)*(z_ball#-z_object#))

if distance#<50
for a=1 to 10
-move ball 5-
-detect collision for ball-
next a
else
-move ball 50-
endif

this would move ball normaly 50 units and only if there is posibility that ball owerstep object then its making substep detection.

Like this you can speed your things up...

arras
22
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 21st Feb 2003 12:29
I just got an idea that another way to speed things up is to store distance datta and to calculate collision only if old distace was smaler than move you actualy do.

Like this you would make collision detect only each second move for objects far away. In fact most object, most of the time are far...

For sure you can reduce it to each 3 or more move and with little bit of coding you can do it depending on old distance walue

for example if two objects are 100 units far and theyr max speed is 10 unit for both then next distance detection will be afther 5 loops because its sure, that they can not colide sooner: if they start to move direction to each other, it will take them 5 loops on maximum speed to get to each other.

Thats just idea, but it should be quit easy to code....

Login to post a reply

Server time is: 2025-05-16 23:34:49
Your offset time is: 2025-05-16 23:34:49