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 and What Happens When

Author
Message
Sir_Herbert
12
Years of Service
User Offline
Joined: 6th Nov 2013
Location: The InterWebz
Posted: 16th Jan 2014 19:19
I am trying to set a collision on my buildings in my world. I am trying to get it so when my object 1 collides with them that you can't move through them. I am also no to sure if I have my collision boxes set up correctly. They collision boxes can be found in the make building section towards the bottom. Thanks



There are three kinds of people in this world. Those that can count and those that can't...
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 16th Jan 2014 22:14 Edited at: 16th Jan 2014 22:21
Personally I have never used/needed collision boxes. Others may swear by them, but I'm not sure.

I just use the objects themselves and detect collisions with OBJECT HIT, OBJECT COLLISION or by using AUTOMATIC CAMERA COLLISION. (For complex objects, Sparky's collision plugin works great.)

I have noticed that when you scale a cube it's a good idea to call SET OBJECT COLLISION TO BOXES after to redefine the new collision area. (At least that's what I remember doing.)

Other native command options are INTERSECT OBJECT and AUTOMATIC OBJECT COLLISION and I'm sure someone will come along with some other ideas soon.

D.D.
SamKM
17
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 16th Jan 2014 23:00
At a quick glance, it looks like you're setting up your collision boxes great, but you're not checking collision with them! If you're going to use collision boxes, you have to do it manually
A quick routine which usually works for keeping objects outside of collision boxes is something like this:

if object collision(1, 2) = 1
collx# = get object collision x()
colly# = get object collision y()
collz# = get object collision z()
position object 1, object position z(1) - collx#, object position y(1) - colly#, object position z(1) - collz#
endif

Hope that helps! Play around with it and see what works best for your buildings. Good luck!
29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 16th Jan 2014 23:13
Hm, SamKM got in with a similar but much better answer than I was going to give but I'll give you my input anyway.

Like Sam mentioned, you've not actually determine if any collisions have been made (in DBPro you have to code everything and at the moment your code is seeing a collision box but doesn't know what you want to do with it).

I wrote a simple driving game a while back which you can find here but you'll have to down a few posts to find an expanded version of the code (with lots of comments) which you can find here:

http://forum.thegamecreators.com/?m=forum_view&t=178125&b=11

It doesn't use collision boxes but does show the basic of detecting and resolving collision. I expect if you combine it with what Sam posted then you should have what you're after.

One thing you might want to do is tidy up the order in which you've create your world, so have your car as object 1, then all the walls 2 to 20 (or however many you have) and then the floors as 21 onward. This should make it easier to sort out the collision detection, especially if you what different response from different collisions (this is something you can see in game I linked to.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 16th Jan 2014 23:25
Hi there.

Same here, I never use collision boxes, and nowaday I use Sparkys but I remember some code I had for DBC that I adapted for Dbpro.


@Sir_Herbert
Here is your code with some modification and my collision subrutine.




I'm not a grumpy grandpa

Login to post a reply

Server time is: 2026-07-06 10:33:39
Your offset time is: 2026-07-06 10:33:39