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 Professional Discussion / Collision Detection

Author
Message
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 3rd May 2013 18:14
Hello,

So basically, I want to stop any objects from going through the object below. I have tried making object collision boxes relative to the object center and relative to the center of the playing field (0,0,0) and turning the object collision on, all with no results. Please help!



-Sa
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 3rd May 2013 18:37
You didn't include your loop in the code, but unless you've written something for handling the collision, your collision box is pretty pointless.
You'll need something like "If object collision(1, 2)=1 then...."
At least that's how I do it.

http://mattsmith.carbonmade.com/
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 5th May 2013 23:45
Quote: "your collision box is pretty pointless.
You'll need something like "If object collision(1, 2)=1 then....""


Indeed! ,,,Setting up object collision, polygon collision etc,,, tells only an object how collisions should be detected, not what should happen when a collision happens.

www.memblockgames.com
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 6th May 2013 18:21
Sorry, I'm still half a rookie at this.

So, I followed your advice, and I made this:
By the way, I just want object 1 to not go through anything. Therefore the IF OBJECT COLLISION(1,(X)))
Thanks!





-Sa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th May 2013 18:50
Quote: "position object 1,object position x(1),object position y(1), object position z(1)"

All this line does is position the object, where the object is, not provide collision.

Although not perfect, this would be better. (But is still awful, and I'd suggest using sparkys collision plugin)


But I stress that this is a horrible way to do it.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 7th May 2013 11:23
You could say that mobiius code throws back the object to it's last collision free zone due to those Old x,,,z variables. But I agree that there is a better way to do this with sparky's collision.

The Dll contains useful commands for doing this. But afterall, it's your code, the possibilities are endless, your decision

www.memblockgames.com
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 7th May 2013 18:18
Erm....
So, I downloaded Sparky's collision, but how do I use it for my situation?
(All the HTML help files seem to have been replaced, or something.)


-Sa
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 7th May 2013 18:34 Edited at: 7th May 2013 18:35
Ok, I installed it correctly now...
But I still don't understand how to use it...?

-Sa
mnemonic
19
Years of Service
User Offline
Joined: 14th Jan 2007
Location: Sweden
Posted: 7th May 2013 23:57
It's a bit tricky at first. Many of the native collision commands in dbpro has couterparts in sparky's only with 'sc' in the beginning.
eg. object collision(1,2) is the same as sc_objectCollison(1,2) in sparky's

and then there are useful commands for getting information about collisions:

sc_getCollisionNormalX()
sc_getCollisionSlideX()

these commands will return the normal, or the slide point (the slide point is where the object would end up if it slid along the face of the collision)

Here's some example code, works pretty lame, but you get the picture



www.memblockgames.com
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 8th May 2013 18:18
Okay,

For some reason, I cannot get sparky's collision to work on my computer. The editor will not even recognize the keywords.
So instead , I tried the code that Mr.Mobiius posted on May 6th, also with no results.
Is it because I am not using a collision box on object three and a SET OBJECT COLLISION TO POLYGONS command instead?







-Sa
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 8th May 2013 18:47
Set object collision to polygons isn't the problem, I use that too. Here's a quick little example I just worked up, hopefully it will help you out. It uses the set object radius command for collision data instead of a collision box.


http://mattsmith.carbonmade.com/
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 9th May 2013 18:10 Edited at: 9th May 2013 18:20
Ok,

I made some progress! The Object 1 has stopped going through Object 3!.... unfortunately only when Object one is moving in reverse!
I tried your suggestion between object 1 and 3, and now it won't go through the object when object one is moving in reverse?
Does anyone know what I am doing wrong?



-Sa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 10th May 2013 13:17
You need to place the oldx variables at the top of the loop. Where I had them in my sample code.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 21st May 2013 18:34
Hello!

Sorry for not replying...
I decided to restart the entire thing, and now I only have one problem :

I want the game to take the player to _WINNER as soon as object one collides with object three... and I tested it... and nothing happened.
Please help!





-Sa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 21st May 2013 18:52
Quote: "if object collision (1,3) > 1 then goto _winner"

1) Never use goto!
2) This line should be in your main loop, as it only gets executed once, and the two objects do not collide.
3) It should be: if object collision (1,3) >= 1 then..... as this command returns 0 and 1 in this form.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 22nd May 2013 18:10
Ok,
I implemented your suggestions, but it still won't work.
Is there something I'm doing wrong?


make object sphere 3,250
position object 3,-250,200,-250
set rainbow shading on 3,4
set object collision to spheres 3



do
if object collision (1,3) >= 1 then gosub Winner
loop

-Sa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 22nd May 2013 18:32
Your not changing the positions of your objects, neither are you syncing to the screen, and your aren't even positioning the camera to see these objects...

You should probably head over to the newcomers section and see some of the tutorials there. Or download sparkys collision plugin and look through the examples provided with that.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 23rd May 2013 18:23
I am actually doing those all.
I took it out so the code would be easier to read.


do
if upkey() then move object 1,5
OldX# = Object Position X( 1 )
OldY# = Object Position Y( 1 )
OldZ# = Object Position Z( 1 )
if downkey() then move object 1,-5
if leftkey() then yrotate object 1, wrapvalue(object angle y(1)-4) : facing# = facing# - 4.5
if rightkey() then yrotate object 1, wrapvalue(object angle y(1)+4) : facing# = facing# + 4.5
set camera to follow object position x(1), object position y(1), object position z(1), facing#, 300, 200, 200, 1
if object collision (1,3) >= 1 then gosub Winner
loop

-Sa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd May 2013 22:27 Edited at: 23rd May 2013 22:28
Your code is still wrong...

Quote: "You need to place the oldx variables at the top of the loop. Where I had them in my sample code."

You still haven't done this..

Quote: "neither are you syncing to the screen,"

You aren't doing this either...

Neither are you actually using the Old# values anyway"!

Here, try this. (Note I've removed your pointless GoSub as you never return from it. This will cause a stack overflow crash)


This code works perfectly...

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 24th May 2013 18:15
Sorry, You were right.

Also, I actually do not want the game to return from the SUB. If they hit it, they win.
That sub only Clears the screen and tells them that they win.
Also, It won't even END like you said in your sample (Thanks for that, by the way. It gave me a better understanding.)



-Sa
SS45
13
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 29th May 2013 18:09
Er.....
You were right. Thank you so much for your help!

-Sa
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 29th May 2013 19:22
No worries.

This is my current project, check it out! [href]forum.thegamecreators.com/?m=forum_view&t=204576&b=8[/href]
This is my website, check it out! [href]http:\\www.TeamDefiant.co.uk[/href]

Login to post a reply

Server time is: 2026-07-07 11:21:05
Your offset time is: 2026-07-07 11:21:05