Using the Nuclear Glory .dll I've finally gotten my platformer engine close to where I want it to be. My only problem at the moment is that when my object touches the platforms sides it can sort of 'walk' right up the sides, and when it hits the bottom of them it sticks to them. I can clearly see in my code why this behavior is happening, and I think I know how to fix it.
I had in my mind to make four collision boxes, for the right side, the top, the left side, and the bottom of the platform, so that when one of them is hit I can make the object react as I want it. Is that going to be too much too calculate though, 4 collision boxes per platform? Obviously I wouldn't load these objects until my character is close to them. I just didn't want to start on some elaborate thing if its going to be too taxing in the long run.
Here's the code:
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
make object sphere 1, 2
position object 1, 0, 0, 50
make object box 2, 4, 1, 4
position object 2, 6, 1, 0
make object box 3, 50, 0.5, 10
position object 3, 0, -1.2, 0
make object box 4, 4, 1, 4
position object 4, -5, 4, 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_BLOCK_ONE=2
#Constant TYPE_FLOOR_BOX=3
#Constant TYPE_ENEMY_BOX=4
StartCollisionPRO(000000000,000000000,000000000)
StartCollisionDebugPRO()
SetCollisionsPRO( TYPE_SPH_OBJ, TYPE_FLOOR_BOX, ELLIP_2_POLY, RESP_SLIDE, DYN_NO_RESP, 0 )
SetCollisionsPRO( TYPE_SPH_OBJ, TYPE_BLOCK_ONE, ELLIP_2_POLY, RESP_SLIDE, DYN_NO_RESP, 0 )
SetCollisionsPRO( TYPE_SPH_OBJ, TYPE_ENEMY_BOX, ELLIP_2_POLY, RESP_SLIDE, DYN_NO_RESP, 0 )
CollisionTypePro( 1, TYPE_SPH_OBJ )
CollisionTypePro( 2, TYPE_BLOCK_ONE )
CollisionTypePro( 3, TYPE_FLOOR_BOX )
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#
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)
if CollCount>0
Obj=CollisionHitObj(1,1)
if Obj>1
gravity#=0.0
jumped=0
endif
endif
if CollCount=0
gravity#=gravity#-0.01
jumped=1
endif
endfunction
Thanks!
Neeeeeeeewom!