I tried to pos this before, but then the thread turned into a convo about e-mails.. so I'll try again...
I can make my ball move around, and it slides around.. (I will post the code in a moment).. now, if you press the up key it will move along the z axis (for example). If you let go of the upkey, if will keep sliding in that direction, even if your facing another direction.. Now, what I want to do (and I need your help), it to make the ball always roll in the direction your going, not facing..
E.G.
if your moving along the z axis, and the ball if facing along the z axis, it shoul;d rotate round the X axis.
Say it keeps going in that direction, but you turn and face the X axis (moving along the z, facing x) the ball should then be x rotating....
I have no idea how to do this.. BUT, perhaps if I could get the angle between the direction im going, and direction im facing, maybe that would help, but I don't know...
Here's the imortant part of the code..
`Setup For Performance
Sync on
Sync rate 60
Hide mouse
set camera range 1,100000
`Create Game Elements
Gosub _Create_Elements
`--Main Loop--
Do
`Control Elements
Gosub _Control_Player
`--End Loop--
Sync
Loop
`---Subroutines---
_Create_Elements:
`Variables
fric#=0.95
speed#=3
`Arrays
`Player
make object sphere 1,100
Return
`Control PLayer
_Control_Player:
`Store old positions
oldx#=x#
oldy#=y#
oldz#=z#
`Check for keys pressed
if upkey()=1 then up=1 else up=0
if downkey()=1 then down=1 else down=0
if leftkey()=1 then left=1 else left=0
if rightkey()=1 then right=1 else right=0
`Physics
if up=1
xspeed#=xspeed#+newxvalue(0,ay#,speed#)
zspeed#=zspeed#+newzvalue(0,ay#,speed#)
endif
if left=1
ad#=wrapvalue(ad#-3.0)
endif
if right=1
ad#=wrapvalue(ad#+3.0)
endif
if up=1
last=1
endif
if down=1
last=2
endif
if up=0 and down=0 and last=1 then last=1
if up=0 and down=0 and last=2 then last=2
if last=1
move#=sqrt((oldx#-x#)^2+(oldy#-y#)^2+(oldz#-z#)^2)
endif
if last=2
move#=(sqrt((oldx#-x#)^2+(oldy#-y#)^2+(oldz#-z#)^2))*-1
endif
ay#=wrapvalue(curveangle(ad#,ay#,5.0))
xspeed#=xspeed#*fric#
zspeed#=zspeed#*fric#
x#=x#+xspeed#
z#=z#+zspeed#
`Update Player
position object 1,x#,y#,z#
yrotate object 1,ay#
`Tracking Camera
ca#=wrapvalue(curveangle(ay#,ca#,20.0))
cx#=newxvalue(x#,ca#,-600)
cz#=newzvalue(z#,ca#,-600)
cy#=curvevalue(y#+300,cy#,10.0)
position camera 0,cx#,cy#,cz#
yrotate camera 0,ca#
point camera 0,x#,y#,z#
`Return to Loop
Return
And a bit of code to find out how fast you're going to determine the speed to roll (already in the main part of the code)
move#=sqrt((oldx#-x#)^2+(oldy#-y#)^2+(oldz#-z#)^2)
Thanks to all those you can help (and I guess those who try)