Hey guys!
As you may know, I am working on a Kirby game(3d), and right now, he jumps, does a triple jump, a long jump, a back-flip, a butt-slam, wall-kicks etc.
Anyway, a problem has occurred with stearing the player. I made it so the player rotates according to the input:
up arrow is 0°, right is 90°, down is 180°, left is 270°
up+right is 45°, right+down is 135°, down+left is 225°, left+up is 315°
if I push up, and then left, the player will rotate from 0° to 270°, making the player turn 270° instead of 90°, which is of course unusual. And I don`t know how to make it rotate the shortest distance. Can someone please help me?
Here is some quick code I copied and pasted(Don`t complain about all of the unused variables):
rem rotating problem
rem by TheComet
rem setup screen
sync on
sync rate 30
backdrop on
color backdrop 0
hide mouse
rem make player
make object cone 1,10
xrotate object 1,90
make mesh from object 1,1
delete object 1
make object 1,1,0
delete mesh 1
rem make objects
make object cube 200,50
scale object 200,100,1000,100
make mesh from object 1,200
delete object 200
make object 200,1,0
position object 200,500,0,500
make object collision box 200,-25,-250,-25,25,250,25,0
make object cube 201,50
scale object 201,100,1000,400
make mesh from object 1,201
delete object 201
make object 201,1,0
position object 201,500,0,680
make object collision box 201,-25,-250,-100,25,250,100,0
make object box 202,50,10,50
position object 202,500,250,500
make object box 203,50,10,200
position object 203,500,250,680
make object cube 204,50
position object 204,400,25,300
for t=202 to 204
make static object t
objx#=object position x(t)
objy#=object position y(t)
objz#=object position z(t)
objsx#=object size x(t)/2.0
objsy#=object size y(t)/2.0
objsz#=object size z(t)/2.0
make static collision box objx#-objsx#,objy#-objsy#,objz#-objsz#,objx#+objsx#,objy#+objsy#,objz#+objsz#
delete object t
next t
rem make matrix
make matrix 1,1000,1000,10,10
randomize matrix 1,25
rem variables
obj=1
dist#=35
roomhide=1
player_speed=2
cay#=0:dist#=50:camheight#=50:smooth#=10
rem main loop
do
rem control camera
if keystate(211)=1 and cam_rotate=0 then inc cay#,45:cam_rotate=1
if keystate(209)=1 and cam_rotate=0 then dec cay#,45:cam_rotate=1
if keystate(211)=0 and keystate(209)=0 and cam_rotate=1 then cam_rotate=0
height#=y#+camheight#
set camera to follow x#,y#,z#,cay#,dist#,height#,smooth#,1
point camera x#,y#,z#
rem move player
yrotate object 1,wrapvalue(ay#)
if grav#=0 and squash=0 and jumpaction=0
if upkey()=1 then nay#=cay#:walking=1
if downkey()=1 then nay#=cay#+180:walking=1
if leftkey()=1 then nay#=cay#-90:walking=1
if rightkey()=1 then nay#=cay#+90:walking=1
if upkey()=1 and rightkey()=1 then nay#=cay#+45
if rightkey()=1 and downkey()=1 then nay#=cay#+135
if downkey()=1 and leftkey()=1 then nay#=cay#-135
if leftkey()=1 and upkey()=1 then nay#=cay#-45
if walking=1 then pm#=curvevalue(player_speed,pm#,5) else pm#=curvevalue(0,pm#,5)
endif
move object 1,pm#
rem get player positions
x#=object position x(1)
y#=object position y(1)
z#=object position z(1)
rem smooth angle
ay#=curvevalue(nay#,ay#,4)
rem collision with objects and matrix
col=object collision(1,0)
if col
if keystate(45)=1
success=1
if y#>object position y(col)+(object size y(col)/2) then success=0
text 0,80,str$(y#)
remstart
if upkey()=1 and nay#=cay# then success=1
if leftkey()=1 and nay#=cay#-90 then success=1
if downkey()=1 and nay#=cay#+180 then success=1
if rightkey()=1 and nay#=cay#+90 then success=1
if upkey()=1 and rightkey()=1 and nay#=cay#+45 then success=1
if rightkey()=1 and downkey()=1 and nay#=cay#+135 then success=1
if downkey()=1 and leftkey()=1 and nay#=cay#-135 then success=1
if leftkey()=1 and upkey()=1 and nay#=cay#-45 then success=1
remend
if success=1 then grav#=5:highestjump=1:ay#=wrapvalue(ay#+180):nay#=ay#:pm#=3:jumpstate=0:longjumpbutton=0:jumpaction=0 else grav#=0
endif
if keystate(45)=0 then jumpbutton=0
dec x#,get object collision x()
dec y#,get object collision y()
dec z#,get object collision z()
endif
g#=get ground height(1,x#,z#)+6
if y#<g#
y#=g#
grav#=0
if keystate(45)=0 then jumpbutton=0
endif
text 0,80,str$(success)
rem Set a size for the player object
s#=5
rem Ensure camera stays out of static collision boxes
if get static collision hit(oldx#-s#,oldy#-s#,oldz#-s#,oldx#+s#,oldy#+s#,oldz#+s#,x#-s#,y#-s#,z#-s#,x#+s#,y#+s#,z#+s#)=1
dec x#,get static collision x()
dec y#,get static collision y()
dec z#,get static collision z()
if get static collision y()<>0.0 then grav#=0.0
if keystate(45)=0 then jumpbutton=0
endif
rem update player positions
position object 1,x#,y#-((100-playersizey)/13),z#
yrotate object 1,wrapvalue(ay#)
rem reset varialbe(s)
walking=0
jump=0
highjump=0
highestjump=0
rem refresh screen
sync
rem end of main loop
loop
Controls are:
up, left, right down to steer player
delete to turn camera left
page down to turn camera right
Many Thanks in advance, TheComet
Suicide is away of telling God, You can’t fire me I quit !!!!!