Advertisement

Collision detection and Arrays

Started by January 04, 2003 08:15 AM
0 comments, last by venomelektro 22 years, 1 month ago
Hello, I m french so please excuse me if my english is bad ... I m building a 3d world from a text file , for the momment there is only 2 kinds of pieces in my world 1 means a floor 2 means a cube I make an object moving throught this world with keyboard If my object move from a floor to another floor -> ok If my object move from a floor to a cube -> return to last position and write "collide" on screen I ve filled an Array called world[][] with my 1 and 2 and declare and int called sens egals to 1 if keys[VK_UP] , 2 -> dow .. etc .. xpos and zpos represents the position of my object last_x and last_z the last position of my object I check if there is a collision like this : void check_collision () { switch (sens) { case 1: if (world[(int)floor(last_x)][(int)floor(last_z)] == 1 && world[(int)floor(xpos)][(int)floor(zpos)] == 2 ) collision=1; break; case 2: if (world[(int)floor(last_x)][(int)floor(last_z+0.5f)] == 1 && world[(int)floor(xpos)][(int)floor(zpos+0.5f)] == 2 ) collision=1; break; case 3: if (world[(int)floor(last_x+0.25f)][(int)floor(last_z)] == 1 && world[(int)floor(xpos+0.25f)][(int)floor(zpos)] == 2 ) collision=1; break; case 4: if (world[(int)floor(last_x-0.25f)][(int)floor(last_z)] == 1 && world[(int)floor(xpos-0.25f)][(int)floor(zpos)] == 2 ) collision=1; break; default: break; } if (collision == 1 ) { zpos=last_z; xpos=last_x; } } And it works fine , but if I pressing simultaneous keys_up and left for exemple , sometimes I can pass throught the cube If anybody can help me , I can send you the dsw project too (visual 6) Thanx
i dont want to put you down, because i started out doing this type of make shift collision detection.

I have some code you can use and learn from to make a great 3d world with perfect detection.

I use an exported ASC file from 3d studio max and i parse it with my own VB program i made so i can read it from my C++ code.

It is very simple and very easy to use

Email if you are interested.

IT Administrator / Software Engineere
http://drdsoftware.cjb.net
Dustin DavisOwner / CEOProgrammers Unlimitedwww.Programmers-Unlimited.com

This topic is closed to new replies.

Advertisement