I can't understand why this isn't working, when i press the direction keys the ball moves but doesn't rotate.
sync on
sync rate 60
autocam off
set image colorkey 255,0,255
color backdrop 0
global radius# as double float : radius# = 10.0
Speed# = 0.0: Rem Starting Speed
SpeedZ# = 0.0
Accell# = 0.0001: Rem Acceleration Rate
AccellZ# = 0.0001
makelevel()
makeplayer()
`player movement vector
global vx# as double float
global vy# as double float
global vz# as double float
global gravity# as double float : gravity# = -0.1
global slope# as double float : slope# = 0.5
global ground as integer : ground = 1
`Start main loop
do
POINT CAMERA X#,Y#,Z#
moveplayer()
`Debug information
set cursor 0,0
print "x:";object position x(2)
print "y:";object position y(2)
print "z:";object position z(2)
print "camera x:";camera position x(0)
print "camera y:";camera position y(0)
print "camera z:";camera position z(0)
sync
loop
function makelevel()
load object "Levels\Simple.x",1
set object cull 1,0
sc_setupcomplexobject 1,1,2
load object "Levels\Warper.x",3
load bitmap "Levels\Warp.bmp",1
get image 1,0,0,256,256 : delete bitmap 1
texture object 3,1
POSITION OBJECT 3,90,11,0
scale object 3,88,88,88
ghost object on 3
position camera x#,150,z#-150
endfunction
function makeplayer()
Load object "Levels\Sphere.x",2
position object 2,-90,135,-30
sc_setupobject 2,0,1
sc_allowobjectscaling 2
`SC_DRAWOBJECTBOUNDS 2
endfunction
function moveplayer()
oldx# = object position x(2)
oldy# = object position y(2)
oldz# = object position z(2)
angy# = object angle y(2)
vx# = 0
vz# = 0
if vy#=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
If UpKey() = 1
Inc Speed#,Accell#
if speed#=<0 then inc speed#,accell#+0.0001
If Speed# > 20.0 Then Speed# = 20.0
vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
Endif
if downkey()=1
dec speed#,accell#
if speed#=>0 then dec speed#,accell#+0.0001
if speed# <-20 then speed#=-20
vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
z#=z#+speed#
endif
if upkey()=0 and downkey()=0
If Speed# > 0.0 Then Dec Speed#,Accell#
if speed# < 0.0 then inc speed#,accell#
If Speed# = 0.0 Then Speed# = 0.0
endif
XRotate Object 1,WrapValue(Object Angle X(1) + Speed#)
if rightkey()=1
Dec SpeedZ#,Accellz#
if speedZ#=>0 then dec speedz#,accellz#+0.0001
if speedz# <-20.0 then speedz# =-20.0
vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
endif
if leftkey()=1
inc speedz#,accellz#
if speedz#=<0 then inc speedz#,accellz#+0.0001
if speedz# > 20.0 then speed = 20.0
vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
endif
if leftkey()=0 and rightkey()=0
If Speedz# > 0.0 Then Dec Speedz#,Accellz#
if speedz# < 0.0 then inc speedz#,accellz#
If Speedz# = 0.0 Then Speedz# = 0.0
endif
Zrotate object 1,wrapvalue(object angle z(1) + Speedz#)
x#=oldx#+vx#
y#=oldy#+vy#
z#=oldz#+vz#
collide = sc_spherecastgroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
ny# = sc_getCollisionNormalY()
if abs(ny#)>slope#
`Flat ground
oldy# = sc_getStaticCollisionY()
else
`Steep slope, cause to slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
`ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
`only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
`If player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
`Nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
`If hit, reposition player, stop movement
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
endif
if object exist (3)
if object collision (2,3)>0 and object position x(2)=>90
set object speed 3,110
play object 3,0,80
for s=100 to 25 step -1
scale object 2,s,s,s
if s=25
radius#=2.5
set object collision off 3
endif
sync
next s
endif
endif
position object 2,x#,oldy#,z#
sc_updateObject 2
if oldy#=<-1000
radius#=10
delete object 2
sc_removeobject 2
set object collision on 3
makeplayer()
endif
if z#=>25
position camera x#,150,z#+150
else
position camera x#,150,z#-150
endif
if z#=>100 then wait 500 : end
endfunction
However i have this bit of code
Sync On: Sync Rate 0
AutoCam Off
CLS: Sync
Ink RGB(255,0,0),0: Box 0,0,255,255
Ink RGB(0,255,0),0
For N=1 To 16 Step 2
Box N*16,0,N*16+16,256
Next N
Get Image 1,0,0,256,256,1
Make Object Sphere 1,1
Texture Object 1,1
Position Camera 0,2,-2
Point Camera 0,0,0
Speed# = 0.0: Rem Starting Speed
SpeedZ# = 0.0
Accell# = 0.0001: Rem Acceleration Rate
AccellZ# = 0.0001
Do
If UpKey() = 1
Inc Speed#,Accell#
if speed#=<0 then inc speed#,accell#+0.0001
If Speed# > 20.0 Then Speed# = 20.0
Endif
if downkey()=1
dec speed#,accell#
if speed#=>0 then dec speed#,accell#+0.0001
if speed# <-20 then speed#=-20
z#=z#+speed#
endif
if upkey()=0 and downkey()=0
If Speed# > 0.0 Then Dec Speed#,Accell#
if speed# < 0.0 then inc speed#,accell#
If Speed# = 0.0 Then Speed# = 0.0
endif
XRotate Object 1,WrapValue(Object Angle X(1) + Speed#)
if rightkey()=1
Dec SpeedZ#,Accellz#
if speedZ#=>0 then dec speedz#,accellz#+0.0001
if speedz# <-20.0 then speedz# =-20.0
endif
if leftkey()=1
inc speedz#,accellz#
if speedz#=<0 then inc speedz#,accellz#+0.0001
if speedz# > 20.0 then speed = 20.0
endif
if leftkey()=0 and rightkey()=0
If Speedz# > 0.0 Then Dec Speedz#,Accellz#
if speedz# < 0.0 then inc speedz#,accellz#
If Speedz# = 0.0 Then Speedz# = 0.0
endif
Zrotate object 1,wrapvalue(object angle z(1) + Speedz#)
Sync
Text 0,0,"Speed: "+Str$(Speed#)+" "
text 0,10,"SpeedZ:"+str$(speedz#)+" "
text 0,20,"X#:"+str$(x#)+" "
text 0,30,"Z#:"+str$(z#)+" "
Loop
which is more or less exactly the same controls as the top bit of coding, and it all workds fine on it's own...
Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD
I can see from your smile, you're not here for the sunset.