I am adding gravity and jumping into me fps project, but it's not liking what I'm doing. Everything works fine if you take out all the code with gravity but when I try to compile it tells me and "Initialisation data '1' is incompatible at line 15 (Global gravity# = 1)
I am using Sparky's for collision
sync on
sync rate 60
`````````Globals`````````````
Global player = 2
Global level = 1
Global playerYColl# = 0
Global playerYNorm# = 0
Global falling = 1
Global plrSpeedF# = 0
Global plrSpeedR# = 0
Global moving = 0
Global canJump = 0
Global falling = 1
Global gravity# = 1
`````````````````````````````
`````````LOAD LEVEL``````````
set dir "Files"
rem load static objects "levelbank/testlevel/universe.dbo",0
load object "levelbank/testlevel/universe.dbo",level rem : hide object 1
make object sphere player,50
position object player,2127,123,-2094
position camera 1856,125,-1835
rotate camera 0,140,0
`````````````````````````````
`````````SETUP Collision`````
sc_setupcomplexobject level,1,2
sc_setupobject player,0,2
`````````````````````````````
do
x$ = str$(camera position x())
y$ = str$(camera position y())
z$ = str$(camera position z())
text 0,0,x$
text 0,50,y$
text 0,100,z$
text 0,150,str$(playerYNorm#)
text 0,200,str$(playerYColl#)
text 0,250,str$(canJump)
moveplayer()
sync
loop
function moveplayer()
rem Old positions
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
rem Input Conrols
if keystate(17)=1 then inc plrSpeedF#, 0.1
if keystate(31)=1 then dec plrSpeedF#, 0.1
if keystate(17)=0 and keystate(31)=0
if plrSpeedF# > 0
dec plrSpeedF#, 0.1
if plrSpeedF# < 0 then plrSpeedF# = 0
endif
if PlrSpeedF# < 0
inc plrSpeedF#, 0.1
if plrSpeedF# > 0 then plrSpeedF# = 0
endif
endif
if keystate(32)=1 then inc plrSpeedR#, 0.1
if keystate(30)=1 then dec plrSpeedR#, 0.1
if keystate(32)=0 and keystate(30)=0
if plrSpeedR# > 0
dec plrSpeedR#, 0.1
if plrSpeedR# < 0 then plrSpeedR# = 0
endif
if PlrSpeedR# < 0
inc plrSpeedR#, 0.1
if plrSpeedR# > 0 then plrSpeedR# = 0
endif
endif
if keystate(32)=1 or keystate(30)=1 or keystate(17)=1 or keystate(31)=1
moving = 1
else
moving = 0
endif
if spacekey() = 1 and canJump = 1
jumping = 1
gravity# = 5
endif
dec gravity#, 0.4
if gravity# < -5 then gravity# = -5
rem Control Cap
if plrSpeedF# > 2 then plrSpeedF# = 2
if plrSpeedF# < -2 then plrSpeedF# = -2
if plrSpeedR# > 2 then plrSpeedR# = 2
if plrSpeedR# < -2 then plrSpeedR# = -2
rem Finalize movement
move object right 2, plrSpeedR#
move object 2, plrSpeedF#
position object 2, object position x(2), object position y(2)+gravity#, object position z(2)
x# = object position x(2)
y# = object position y(2)
z# = object position z(2)
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,y#,z#,30,0)
if collide>0
x# = sc_getCollisionSlideX()
y# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
playerYColl# = y# - sc_getStaticCollisionY()
endif
position object 2,x#,y#,z#
playerYNorm# = sc_getCollisionNormalY()
rem position the camera
position camera object position x(2),object position y(2),object position z(2)
rem camera control/player movement
rotate camera camera angle x(0)+(mousemovey()/2.0),camera angle y(0)+(mousemovex()/2.0),0
cx#=camera angle x(0) : cy#=camera angle y(0)
if wrapvalue(camera angle x(0))>40 and wrapvalue(camera angle x(0))<180 then xrotate camera 0,40
if wrapvalue(camera angle x(0))>180 and wrapvalue(camera angle x(0))<280 then xrotate camera 0,280
yrotate object 2,camera angle y()
position camera 0, camera position x(), camera position y()+20, camera position z()
endfunction
rem ###########
if memblock exist(1) then delete memblock 1
rem ###########
Ventures of the worlds around us are only limited by imagination.