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 / Sparky's Collision help.

Author
Message
Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 6th Jul 2008 02:25
Alright here is my Sparky's code so far, I can't get it to work, even if in the function I ask it to print out the rays position, it says it's in the right place, but it won't register any collision.
I have never used Sparky's, I'm using it now to speed up collision.
Any help would be appreciated.




Satchmo
20
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 6th Jul 2008 19:59
Can anybody help?

Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 6th Jul 2008 23:23
I've never used Spaky's collision. Sorry.

I think NanoGamez Guy has used Sparky's. Unfortunately he doesn't go on these forums much.


Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 7th Jul 2008 01:23 Edited at: 7th Jul 2008 02:14
Have you tried giving the zombies their own group? I've found that collision sometimes doesn't work if you assign an object a group number of 0 (in DBP at least). This would be done in the setup command of course.

NanoGamez guy
18
Years of Service
User Offline
Joined: 13th Jan 2007
Location: Closer than you think...
Posted: 7th Jul 2008 18:52 Edited at: 7th Jul 2008 18:54
I haven't acutally used sparky's collision, but I can recommend a tip to check for collision between zombies (or trees).

Instead of using collision, you could use a distance calculation to calculate the distance between 2 zombies
( sqrt( (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ) ).
If two zomibes are close enough , i.e. just touching, then collision=1.

But to save valuable fps, get rid of the sqrt (it uses tons of memory) and use squared values. For example:



would become:



You could use this for trees and other objects that are round (enough).


Did you know - 12% of Americans believe Joan of Arc was Noah's wife.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Jul 2008 00:18
@Satchmo
This question sounds familiar...

In your code



you are not setting a variable to the return value of interscetObjectDBC. Get rid of bang=collide and rewrite the line to read:



Also, make sure you setup the zombies to use sparky's collision before checking for the ray intersection:



One thing to note about using this ray-casting type colliion, it only checks for ray/plane intersection one direction at a time. That means to detect collision above, to the sides, behind, below - you'd have to cast a ray in all of those directions. And if you had a tall character and cast a ray from it's midpoint forward for example, you'd miss forward detection at it's feet or head. This type of collision is great for projectiles, or for contact with a terrain, but it's not ideal for multiple objects that could be bumping into each other from multiple directions.

To Nano's suggestion:
Might want to run some benchmarks (see if it could be faster than Sparky's ray casting for each object in multiple direction) to compare it to Sparky's.

It may be faster, but then again you'd have to do distance checks between each object which could be on a scale of total objects x total objects as opposed to total objects x 5 (assuming one ray cast from center front,back, side,side, top; or total objects x 20 (assuming 4 rays cast from each edge of a plane in each direction to ensure a wider area of detection). It depends on the total objects and the speed of the DLL versus the DBC calcs and how many rays you want to cast. The accuracy would probably be better with the distance check.

And one might be able to squeeze out a bit more speed by also eliminating ^2 in the distance calc:



Enjoy your day.

Login to post a reply

Server time is: 2025-06-06 00:18:24
Your offset time is: 2025-06-06 00:18:24