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 / object collsion!

Author
Message
DB newbie
19
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 26th Nov 2005 00:48
ok i know there are a lot of post about object collision but not like this ok i need some help i loaded a CShop map in DB it works fine ok but i need to know is there a way so that when the camera or object comes into collision with a wall it will kinda slide along it because when it runs into a wall it just goes straight through!

ATI mobility radeon X600 graphics card
AMD 64 Bit processor
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 26th Nov 2005 01:20 Edited at: 26th Nov 2005 01:21
Say your player was object 1.

The idea is, whenever you move the player, you check if it's in the wall. If it is, then you quickly move the player back again before the next 'sync' command.

A quick, playable example:
Quote: "sync on
sync rate 70

make object plain 2,20.0,20.0
rotate object 2,0,0,0
make object cube 1,10.0
`Don't spawn the cube stuck in the middle of the obstacle
move object 1,-100.0:move camera -130.0
set global collision on
color object 1,rgb(255,0,0)
color object 2,rgb(0,255,0)
do
if upkey()=1
move object 1,1.0:move camera 1.0
if object collision(1,0)>0 then move object 1,-1.0:move camera -1.0
endif
if downkey()=1
move object 1,-1.0:move camera -1.0
if object collision(1,0)>0 then move object 1,1.0:move camera 1.0
endif
sync
loop
"


Note how you can't move the red cube through the green thing, and it just stops.

The bit of the code that you need is the part that checks if object 1 collides with anything (having the 2nd param set to 0 makes it return the number of the object it's colliding with or 0 if nothing). If the object is touching the green object, then the red object is quickly moved back.

The use of sync on stops the user from seeing this 'flickering' effect, as you only update the screen when you want, which just happens to be *not* when you are moving the cube.

[Edit] Oh yeah, and don't forget to turn collision on... 'Set Global Collision On' is kind of cheating, because you normally turn collision on individually for each object. That way you can control accuracy, etc. [/edit]

16-colour PNGs pwn.
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 26th Nov 2005 01:26
As a little extension to what Blanky was saying, 'slippery' collision is done similar to that. The procedure is very straightforward. Basically what happens is, when a collision is detected, rather than put the object back where it was before, put it back on only the X dimension, leaving the new Z coordinate intact. If a collision is still detected, put it on the new X coordinate and move it back to its old Z coordinate. If a collision is still detected, put it back into its original position.

Tempest - P2P UDP Multiplayer Plugin - 62%
DB newbie
19
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 26th Nov 2005 02:24
ok thanks a lot that should help!

ATI mobility radeon X600 graphics card
AMD 64 Bit processor
DB newbie
19
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 26th Nov 2005 16:55
is there a way to make it so when the camera hits it it will do the collsion because that would be nice right now im only testing some stuff to get the hang of it!

ATI mobility radeon X600 graphics card
AMD 64 Bit processor
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 26th Nov 2005 17:23
I believe not, the commands are object hit() and object collision()

Since the camera isn't actually an object I don't think you can. You could however at the start of every loop, add this:

position camera object position x(1),object position y(1),object position z(1)
rotate camera object angle x(1),object angle y(1),object angle z(1)

your controls move object 1 (or whatever) around, and if object 1 is hidden, it appears like you're checking for camera collision.

...maybe one day I'll finish a project
blanky
20
Years of Service
User Offline
Joined: 3rd Aug 2004
Location: ./
Posted: 26th Nov 2005 19:45
Either that, or get Sparky's DLL for DBC and start using intersectObject().

Really nice command, lets you send out a line (basically) and tells you if anything collides with it.

Although it doesn't sound much, with that alone you can achieve gravity, physics, bullet decal alignment (there's a couple more commands), and bullet shooting. And collision, of course.

Which is slightly complicated to make work, but wonderful when it does.

16-colour PNGs pwn.
DB newbie
19
Years of Service
User Offline
Joined: 13th Nov 2005
Location: um..... i dont remember.
Posted: 26th Nov 2005 21:21
ok ill try that guys or i will just use a object ok!

ATI mobility radeon X600 graphics card
AMD 64 Bit processor

Login to post a reply

Server time is: 2025-05-22 23:35:18
Your offset time is: 2025-05-22 23:35:18