Hey, I was trying to get the y position of whatever object my object collides with, but something is awry with the CollisionHitObj command and how I'm using it.
CollCount=CountCollisionsPro(1)
cpt#=CollisionHitPoint(1,1,2)
z=CollisionHitObj(1,1)
oby#=object position y(z)
if CollCount>0
Obj=CollisionHitObj(1,1)
if Obj>1 and cpt#>oby# and cpt#<oby#+0.6
gravity#=0.0
jumped=0
else
gravity#=-0.01
endif
endif
if CollCount=0
gravity#=gravity#-0.01
jumped=1
endif
when I use this in my collision function the program fails to run. When I remove the z=CollisionHitObj(1,1) line it works fine... that is it actually brings up the error that Object Position Y(z) doesn't make sense rather than just nothing.
Is there something wrong with my usage of it, and is there any way that I could simply get the y position of whatever object I collide with since the "object position y(z)" doesn't seem to be working since it needs an integer...
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
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)
cpt#=CollisionHitPoint(1,1,2)
z=CollisionHitObj(1,1)
oby#=object position y(z)
if CollCount>0
Obj=CollisionHitObj(1,1)
if Obj>1 and cpt#>oby# and cpt#<oby#+0.6
gravity#=0.0
jumped=0
else
gravity#=-0.01
endif
endif
if CollCount=0
gravity#=gravity#-0.01
jumped=1
endif
endfunction
I figured it out, but as usual trudging forward has created more problems. My object just continues to move into the object it collides with slightly, which causes it to be unable to move until it slowly slides back out. Its not a huge problem but something I'd like to work out early. Meh
Neeeeeeeewom!