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 / Sliding collisions better than db's example

Author
Message
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 8th Apr 2003 21:21
first, I have to tell you that I speak french ; I'll do some errors in my translation, but ... I'm sure that you are enough smart to understand what I'll say }:>

the ones who had dbc before dbp remimber the example number 25 about the sliding collisions, it was good, but it can be better
the big problem with this code is that you can climb a crate from it's side, there is no difference between the top or the bottom of a crate and it's side.
I made a code with trigonometry that look which side is hit. there's only one small problem : the player can hit only one box at the same time, or there will be a problem (but it can be repared with a for next loop (I don't use this system because it's a bit slower and in my game, I won't hit two boxes at the same time))
because I'm a man very kind, I give you this code, with an example :

`»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»
`» 04-08-2003 // 19:11:45 »
`» code made by Atreides »
`» I hope that you will »
`» enjoy this small code »
`»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»»

autocam off
set display mode 1024,768,16
sync on
sync rate 50
set text size 18

rem the universal texture
create bitmap 1,128,128
set current bitmap 1
for x=1 to 128
for y = 1 to 128
dot x,y,rgb(rnd(255),rnd(255),rnd(255))
next y
next x
get image 1,1,1,128,128
set current bitmap 0

rem the play : the sphere
make object sphere 1,5
texture object 1,1
position object 1,0,15,0


rem the ground
make object box 2,250,4,250
texture object 2,1

rem be careful : if the player can hit two boxes at the same time => problem
make object box 3,20,40,20
position object 3,15,35,0
texture object 3,1

make object cube 4,18
position object 4,0,20,30
texture object 4,1

make object cube 5,16
position object 5,0,30,90
texture object 5,1

make object cube 6,14
position object 6,-60,40,90
texture object 6,1

make object cube 7,12
position object 7,-120,50,90
texture object 7,1


do
rem we ask the coordinates of the object
x# = object position x(1)
y# = object position y(1)+grav#
z# = object position z(1)
rem as in the dbc's example
dec grav#,0.0981

rem the object must me moved by modification of its coordinates
if upkey()=1 then x# = x# + sin(object angle y(1))
if upkey()=1 then z# = z# + cos(object angle y(1))
if downkey()=1 then x# = x# - sin(object angle y(1))
if downkey()=1 then z# = z# - cos(object angle y(1))
if leftkey()=1 then yrotate object 1,wrapvalue(object angle y(1)-3)
if rightkey()=1 then yrotate object 1,wrapvalue(object angle y(1)+3)
position object 1,x#,y#,z#
rem have you ever dreamed to fly ?
if controlkey()=1 then grav# = 0.5
rem caméra
set camera to follow x#,object position y(1),z#,object angle y(1),50,object position y(1)+10,10,0
point camera x#,y#,z#


rem here's the code
coll = object collision(1,0)
if coll > 0
dax# = dax(1,coll)
ax# = ax(coll)
day# = day(1,coll)
ay# = ay(coll)
daz# = daz(1,coll)
az# = az(coll)
rem is the player on the crate ?
if dax# > (360 - ax#) or dax# = (360 - az#) or daz# = az# and daz# ay# and day# (180+az#)
if day# (180+ay#)
x# = object position x(coll) - (object size x(coll)/2) - (object size x(1)/2)
position object 1,x#,y#,z#
endif
endif
rem face z - 1
if dax# (180+ax#)
if day# (180-ay#)
z# = object position z(coll) - (object size z(coll)/2) - (object size z(1)/2)
position object 1,x#,y#,z#
endif
endif
rem la face Z + 1
if dax# > ax# and dax# (360-ay#) or day# (180-az#)
if dax# (180-ax#)
rem -0.01 pour que le contacte se coupe, sinon, avec grav# = 0, on reste collé
y# = object position y(coll) - (object size y(coll)/2) - (object size y(1)/2) -0.01
position object 1,x#,y#,z#
rem mais attention, quand on s'éclate au plafond, on retombe tout de suite
rem sauf dans les dessins animés, quand le héro passe à travers le toit
grav# = 0
endif
endif
endif
sync
loop

remstart
I'm sorry, but I cannot explain it well.. the 3 first functions give the
angles between the center of the object and one of its corners ; the 3 last
give the angles between the 2 objects .. it are the functions that are used upper
remend
function ax(obj)
sz# = object size z(obj)/2
sy# = object size y(obj)/2
if sz# > 0
if sy# > 0 then angle# = atan(sz#/sy#)
if sy# 0 then angle# = 360 - atan(abs(sz#)/sy#)
if sy# 0 then angle# = 0
if sy# 0
if sz# > 0 then angle# = atan(sx#/sz#)
if sz# 0 then angle# = 360 - atan(abs(sx#)/sz#)
if sz# 0 then angle# = 0
if sz# 0
if sy# > 0 then angle# = atan(sx#/sy#)
if sy# 0 then angle# = 360 - atan(abs(sx#)/sy#)
if sy# 0 then angle# = 0
if sy# 0
if distz# > 0 then angle# = atan(distz#/disty#)
if distz# 0 then angle# = 180 - atan(distz#/abs(disty#))
if distz# 0 then angle# = 0
if distz# 0
if distz# > 0 then angle# = atan(distx#/distz#)
if distz# 0 then angle# = 360 - atan(abs(distx#)/distz#)
if distz# 0 then angle# = 0
if distz# 0
if disty# > 0 then angle# = atan(distx#/disty#)
if disty# 0 then angle# = 360 - atan(abs(distx#)/disty#)
if disty# 0 then angle# = 0
if disty#
Bu$herie
How many civilians is he going to kill ? he's going to burn in hell, and I hope that his pain will make him inderstand !
Terabyte
23
Years of Service
User Offline
Joined: 28th Dec 2002
Location: UK
Posted: 8th Apr 2003 21:29
typical sods law ive just poseted somet asking for sliding collision

I have a word of advice...
..don't piss on an electric fence!
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 9th Apr 2003 18:26
Frobscottle, I told you that I don't speak well english
I don't understand your answer. "poseted" isn't in my dictionary (a big one!), is it "posted" ? and I didn't find "somet" either ..
talk to me as at a 8 years old boy, so I'll might be able to understand

Bu$herie
How many civilians is he going to kill ? he's going to burn in hell, and I hope that his pain will make him inderstand !
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 9th Apr 2003 19:48
A spider was probably writing the message...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 9th Apr 2003 20:25
oh, I didn't see that it didn't post the whole message .. I send it again, but (im sorry), the rem aren't translated

Bu$herie
How many civilians is he going to kill ? he's going to burn in hell, and I hope that his pain will make him inderstand !
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 9th Apr 2003 20:27
:-s uhh ? it didn't post ? :-s yeah, the sods law is true

I hope that this time it will work

Bu$herie
How many civilians is he going to kill ? he's going to burn in hell, and I hope that his pain will make him inderstand !
Richard Davey
Retired Moderator
24
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 9th Apr 2003 20:31
Why not post it in the "Source Code" box beneath the message box!! Then it's guaranteed to display properly.

Cheers,

Rich

"Gentlemen, we are about to short-circuit the Universe!"
Attreid
23
Years of Service
User Offline
Joined: 27th Nov 2002
Location:
Posted: 10th Apr 2003 22:37
héhé, I posted if the box beneath the message box (in my third message), Rich, but it didn't work
but .. what do you think about my system ? shall I modify something ? is it a good system or a faliure as my other programms ?

Bu$herie
How many civilians is he going to kill ? he's going to burn in hell, and I hope that his pain will make him inderstand !

Login to post a reply

Server time is: 2026-07-11 04:23:57
Your offset time is: 2026-07-11 04:23:57