I'm using DarkBASIC Pro and the Nuclear Glory Collision .dll to build a bit of a 3D platformer thats on a 2D plane. Everythings gone quite well except one thing... something that everyone always takes for granted in games. When I hit the side of my object with my character I want him to slide down as if gravity is still working as normal, even if the player continues to hold down the direction key.
In my code, the object will proceed into the collision box slightly, causing the fall to stop while it slowly slides back outside the collision box until its not colliding and can fall to the ground. If the player holds the direction into the box he's colliding with then the object falls slowly to the ground. I've tried making my speed variable 0.0 when there's collision, but the object always goes slightly into the box...
I'm pretty sure a good deal of the problem with my gravity is that the main character object is constantly going from colliding with the object to being pushed back, therefore not touching it. When the leftkey is held it continues switching back and forth so the gravity variable can't keep building up but rather keeps starting over.... I can't think of any way to fix this though.
Is there any way to remedy these problems?
Thanks
sync on:sync rate 60
REM All the pretty variables
global speedr#
global speedl#
global posx#
global posy#
global posz#
global jumpy#
global jumped
global gravity#=0.3
global obj
global obytwo
global objsx#
global mnobjx#
global rtc#
global ltc#
make object sphere 1, 2
position object 1, 0, 0, 50
make object box 2, 50, 0.5, 10
position object 2, 0, -1.2, 0
make object box 3, 4, 1, 4
position object 3, 6, 1, 0
make object box 4, 4, 5, 4
position object 4, -5, 2, 0
REM Nuclear Glory Stuff
#Constant NCULL_COUNTER_CLOCK 1
#Constant NCULL_CLOCK 2
#Constant NCULL_NONE 3
#Constant TYPE_NGC_ELLIP=1
#Constant TYPE_NGC_MESH=2
#Constant ELLIP_2_ELLIP=1
#Constant ELLIP_2_POLY=2
#Constant RESP_STICK=1
#Constant RESP_SLIDE=2
#Constant RESP_SLIDE_NO_SLOPES=3
#Constant RESP_SLIDE_NO_GRAV=4
#Constant RESP_SLIDE_NO_ACCEL=5
#Constant RESP_NONE=6
#Constant DYN_NO_RESP=1
#Constant DYN_RESP=2
#Constant DYN_RESP_NOTURN=3
#Constant TYPE_SPH_OBJ=1
#Constant TYPE_FLOOR_BOX=2
#Constant TYPE_BLOCK_ONE=3
#Constant TYPE_ENEMY_BOX=4
StartCollisionPRO(000000000,000000000,000000000)
StartCollisionDebugPRO()
SetCollisionsPRO( TYPE_SPH_OBJ, TYPE_FLOOR_BOX, ELLIP_2_POLY, RESP_SLIDE_NO_GRAV, DYN_NO_RESP, 0 )
SetCollisionsPRO( TYPE_SPH_OBJ, TYPE_BLOCK_ONE, ELLIP_2_POLY, RESP_SLIDE_NO_GRAV, DYN_NO_RESP, 0 )
SetCollisionsPRO( TYPE_SPH_OBJ, TYPE_ENEMY_BOX, ELLIP_2_POLY, RESP_SLIDE_NO_GRAV, DYN_NO_RESP, 0 )
CollisionTypePro( 1, TYPE_SPH_OBJ )
CollisionTypePro( 2, TYPE_FLOOR_BOX )
CollisionTypePro( 3, TYPE_BLOCK_ONE )
CollisionTypePro( 4, TYPE_ENEMY_BOX )
SetObjRadiusPRO( 1, 1, 1, 1 )
SetCollisionExclusive( 1 )
REM End Nuclear Glory stuff
do
coll()
keyctrl()
REM make camera follow character
position camera object position x(1), 5,-20
print "FPS: ", str$(screen FPS())
print "right speed: ", speedr#
print "left speed: ", speedl#
print "jumpy#: ", jumpy#
print "gravity#: ", gravity#
print "obytwo#: ", obytwo#
print "objsx#: ", objsx#
print "mnobjx#: ", mnobjx#
print "rtc#: ", rtc#
RunCollisionPRO()
sync
loop
REM Controls
function keyctrl()
REM move right
if rightkey()=1
speedr#=speedr#+.003
else
speedr#=speedr#-.003
endif
REM move left
if leftkey()=1
speedl#=speedl#+.003
else
speedl#=speedl#-.003
endif
REM jumping
if spacekey()=1 and jumped=0
jumped=1
gravity#=0.3
endif
if jumped=1
jumpy#=object position y(1)+gravity#
endif
REM limit speed
if speedr#=>0.3 then speedr#=0.3
if speedl#=>0.3 then speedl#=0.3
if speedr#=<0.0
speedr#=0.0
endif
if speedl#=<0.0
speedl#=0.0
endif
PositionObjectPRO( 1,object position x(1)+speedr#-speedl#,jumpy#,0)
endfunction
function coll()
CollCount=CountCollisionsPro(1)
oby#=object position y(1)
if CollCount>0
Obj=CollisionHitObj(1,1)
objsx#=object size x(obj)/2.0
rtc#=object position x(obj)+objsx#-.1
ltc#=object position x(obj)-objsx#
obytwo#=object position y(obj)
mnobjx#=object position x(1)
if Obj>1 and oby#>obytwo#
gravity#=0.0
jumped=0
else
gravity#=-0.01
endif
If Obj>2 and mnobjx#>rtc# and leftkey()=1
jumped=1
speedl#=0.0
endif
endif
if CollCount=0
gravity#=gravity#-0.01
jumped=1
endif
endfunction
Neeeeeeeewom!