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 / Single-Box Collision Concept

Author
Message
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 26th Oct 2013 18:25 Edited at: 13th Jun 2015 19:04
I don't know if this idea is well known or relatively unheard of, but I was looking for a simple catch-all collision method for a forest of trees and so below is what I came up with.

The idea is to do a standard distance check each loop and place a single cube in the closest tree's position (with adjustments made for height) and simply use that single box for all possible tree collisions. You could also adjust the box's radius depending on the size of the object in question.

(Low FPS is because of my computer, not the code)


So far it works great. I would post a video but my computer is too slow to run FRAPS!

Attachments

Login to view attachments
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 26th Oct 2013 18:44 Edited at: 26th Oct 2013 18:47
Hmm...
Would a sphere or cylinder make more sense, rather than having a cube with edges? Or perhaps point the box towards the player at all times?

D.D.
Mobiius
Valued Member
22
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 26th Oct 2013 18:58
Would it not be easier to use Sparkys collision plugin to handle the collisions??

Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 26th Oct 2013 19:21
Quote: "Would it not be easier to use Sparkys collision plugin to handle the collisions??"


Possibly, but the coding for this technique is minimal, and I like using stuff I came up with on my own.

D.D.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 26th Oct 2013 19:30
Natively, your tree can contain a cube, or a series of cubes object bounds via the Set Object Collision To Boxes command, or MAKE OBJECT COLLISION BOX Object Number, X1, Y1, Z1, X2, Y2, Z2, Collision Flag command.

But there is not much wrong with what you appear to be doing; only you are not using the faster collision functions Mobiius mentioned.

chafari
Valued Member
19
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th Oct 2013 21:20
Quote: " I like using stuff I came up with on my own"


So do I...

Yes, it is possible to use a box to check collision with every tree or perhaps a cylinder...that depends on the accuracy you need. I like sparkys, and I use it in most of my projects.I have also my own system from the Darbasic Clasic, that works ok but no so fast.

As our friends comment, the best way to go is Sparkys, and even when we say "we don't like plug-in", all dll that comes with Dbpro are plug-in somehow...but that is true, some times enjoy more our own stuff.

Cheers.

I'm not a grumpy grandpa
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Oct 2013 01:54
If your really interesting in the collision maths aspect, take a look into rigid body collision. A lot of physics involved but worth a read.

"Get in the Van!" - Van B
Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 27th Oct 2013 03:11
Quote: "Natively, your tree can contain a cube, or a series of cubes object bounds via the Set Object Collision To Boxes command, or MAKE OBJECT COLLISION BOX Object Number, X1, Y1, Z1, X2, Y2, Z2, Collision Flag command."



At first I tried to mess around with SET OBJECT RADIUS, but since my trees are scaled to all different sizes I had a hard time getting a universal formula to work... I think this is because the object's overall radius was based on the widest part of the tree which would be the branches instead of the trunk.

I didn't try MAKE OBJECT COLLISION BOX, but I'm guessing that with multiple collision boxes DBPro has to check for collision with every object, so I just figured why not just use 1 box for everything and use distance checks to find the closest tree.

It doesn't seem that slow to me, but I'd have to code side-by-side comparisons to see how much FPS I'm giving up compared to Sparky's and what Chris suggested.

D.D.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Oct 2013 09:30 Edited at: 27th Oct 2013 09:31
Roger that. In Valve Source (EG: Portal, Counter Strike GO, etc) the collision mesh for trees are pre-constructed in modelling programs and the entity configuration files; function objects are also added in the Hammer editor. These prevent the player from walking into a tree without being blocked by it; allowing FPS players to walk around the tree without much movement cost. Only when close to the tree does a collision check need to occur; their trees are activated by their portal systems (visleaf culling).

I believe their physics entities have a cylinder option so that the shape of the trees collision mesh is calculated by the engine without any mesh. Similar to PhysX cylindrical static rigid bodies.

Something that might inspire some more ideas.

Derek Darkly
13
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 27th Oct 2013 16:46
Thanks, Chris!

I'm hoping that I can find the best ratio between my box (or cylinder) size and the distance setting for the automatic camera collision (or dummy object if I end up going that way.)

I'm really not looking for perfection, just wanna make a made-from-scratch shooter with decent flora and probably some models from the TGC store while I'm still learning modeling myself.

After I nail this tree thing I'll try to do the same with random rocks.

D.D.

Login to post a reply

Server time is: 2025-05-15 23:03:44
Your offset time is: 2025-05-15 23:03:44