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 / Best way to Collision detect a medium sized city

Author
Message
That Guy
20
Years of Service
User Offline
Joined: 20th Jun 2004
Location: New Zealand
Posted: 21st Jul 2004 20:14
Ok so I want to try to find out the best way to collision detect a city currently I load every single object seperatly and position it in the world using the co-ordinates 0,0,0 (it positions everything correctly because I exported the models that way) each building (at the moment cubes) have another box on the roof so I can just reposition the players y position instead of x,y and z (is this alright or is there a better way).
When the player collides with a main part of a building or wall or pole, etc. I reposition the players x and z co-ordinates (this also works fine).
Heres the main problem with my code I collision detect all the barriers (walls, trees, buildings, etc) then the ground and roofs (if there is no collision with these take one away from the players y position) and all this works except I will end up getting a really really low frame rate when I put in a lot of objects is there a better way of doing this, someone please help.

"I am a worm before i'm a man i was a creature before i could stand"
My setup: Toshiba TE2100, geforce4 420go, pentium 4 1.8ghz, 256mb DDR-RAM
That Guy
20
Years of Service
User Offline
Joined: 20th Jun 2004
Location: New Zealand
Posted: 21st Jul 2004 20:18
Ok i've just had an idea please tell me if this will work (im currently not home for a while).
What if I position large invisible boxes over main parts of the city and whatever one the player is colliding with it'll detect if the player is colliding with any objects that are also colliding with that box.

"I am a worm before i'm a man i was a creature before i could stand"
My setup: Toshiba TE2100, geforce4 420go, pentium 4 1.8ghz, 256mb DDR-RAM
AsriCE
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 21st Jul 2004 20:37
If you want to stick with your collision algorithm there, then here are some tips on how you can speed things up.

- Do some distance checks between the player and the level. If the player is far from the chunks of the level, then you can skip the collision check.



- And again, since the SQRT command is an iteration function, it tends to be expensive to calculate. So instead, try squaring the equation, and check for then "Squared-Furthest-Distance" instead.

- Try hiding objects that are not in view.

But there are always other alternatives like using NGCollision DLL, it works quite fast. Hope that helps.

AsriCE Crew,
- Adi

There's only one hope.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st Jul 2004 20:37
If your using a grid of any sort - like a matrice, and you keep within the constraints of the grid, you can use array collision. Like each tile on your city could have it's own height - and checking collision with a system like that is so easy it's funny.

When you adopt array collision, you simply check the array with an integered coordinte, like assuming each tile on your map is 100x100 DB units, you'd divide the player position by 100...

COLX=int(Playerx#/100)
COLZ=int(Playerz#/100)
COLH=Collision_Height(colx,colz)

If you need more help with array collision, check out my 2D rpg demo (2D forum) - it uses height arrays for all the collision and gives nice sliding collision, jumping, pretty much everything you'd need.


Van-B


Muhahahahaha.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 21st Jul 2004 20:53
I've just been experimenting with creating a very basic 3D game, in my early efforts to learn DB - where you control a car that moves through a city.

What I did, and it seems to work reasonably well, is to create the whole city (just a load of boxes for the buildings actually) in Cartography Shop, then export it as a single .x file. Then in DBPro I only have two objects to worry about to begin with -my car and my city.

I then figured out (by reading various threads on this board late last night) that you need to use the 'intersect object' command to detect when the object collides with any part of the city. Programming the collision bit was tricky (for me anyway) but in the long run I think it will be much quicker and easier this way than having your city made of multiple objects. There are also some bits of code around that you can use/buy for the collisions (which I didn't use because I did this purely as a learning activity).

Richard
That Guy
20
Years of Service
User Offline
Joined: 20th Jun 2004
Location: New Zealand
Posted: 22nd Jul 2004 18:49
Ok thanks for the help everyone I think I kind of have it figured out i've just got to fiddle around with it a bit and try a few of the above methods.
Thanks for the help guys
And I dont really want to use the NG plugin because I need practise at doing it all myself it helps me learn the code better then I can get into the plugins

"I am a worm before i'm a man i was a creature before i could stand"
My setup: Toshiba TE2100, geforce4 420go, pentium 4 1.8ghz, 256mb DDR-RAM

Login to post a reply

Server time is: 2025-06-09 04:49:05
Your offset time is: 2025-06-09 04:49:05