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 / Collision help!

Author
Message
Tucker S
9
Years of Service
User Offline
Joined: 15th Oct 2010
Location:
Posted: 15th Oct 2010 18:45


Why do I go through walls? Please help.

I tried two different collision methods and both failed :/
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 16th Oct 2010 05:09
Hello Tucker S,

In order for collision to work, you not only have to set it up for your objects, but you also have to test for it using

OBJECT COLLISION(object1,object2 or 0)
OBJECT HIT(object1,object2 or 0)
or
GET STATIC COLLISION HIT( oldx1,oldy1,oldz1,oldx2,oldy2,oldz2,nx1,ny1,nz1,nx2,ny2,nz2)

As it seems you are using make object collision box, the collision command you'd probably want to use to detect collision would be OBJECT COLLISION().

Your code is a bit hard to follow, with a lot of jumps (gotos) and commented out code, as well as the quotation marks all seem to have an escape character in front of them \" , so I couldn't really figure out where you would want to test for collision in your code. Therefore I knocked together a quick example of the type of collision I think you are after. Use the up and down arrow key to move towards or away from the sphere. When the cube collides with the sphere a message will be displayed.



Enjoy your day.
Tucker S
9
Years of Service
User Offline
Joined: 15th Oct 2010
Location:
Posted: 18th Oct 2010 18:40
Thanks latch, but what I'm looking for is collision with walls so my object doesn't go through them. What code should I use to make my object stay within the boundaries of the walls?

Thanks
Latch
14
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 18th Oct 2010 23:28
Hello,

The principal is basically the same. In the above example, when the objects collide, a value is returned. If the value is zero, there is no collision. If there is a value (1 or the object number) returned by the collision, then you have to decide what to do next like make whatever is hitting a wall go back to the position it was at before it hit the wall.

Instead of launching into a detailed description here, take a look at TDK's Tutorials. There is an in depth discussion on collision. If after reading through that and trying the examples, if you still have questions, please ask. The link is below (and also stickied at the top of the forum board).

TDK Tutorials

Enjoy your day.

Login to post a reply

Server time is: 2020-08-12 01:35:10
Your offset time is: 2020-08-12 01:35:10