My apologies - too much caffeine
- I forgot to add x-axis *rotation* of the camera
. Try this:
rem First we make a character object
Make Object Cube 1,25
rem Now a simple world is made
Make Matrix 1,2500,2500,15,15
rem Start a loop
SYNC ON : DO
rem Allow movement of our character object using the arrowkeys
If Upkey()=1 then Move Object 1,3
If Downkey()=1 Then Move Object 1,-3
If Leftkey()=1 Then yangle#=Wrapvalue(Object Angle Y(1)+3.0)
If Rightkey()=1 Then yangle#=Wrapvalue(Object Angle Y(1)-3.0)
rem Update object's y angle
Yrotate Object 1,yangle#
rem Now we handle the camera
`If user presses right mouse button, alter camera angle value but adding the angle value to the mouse's movement in the x-axis
If mouseclick()=2
camyangle#=Wrapvalue(camyangle#+Mousemovex())
camxangle#=camxangle#+MousemoveY()
Endif
`Apply limits on the camera x angle (i.e. y position) - this way camera is prevented from going up too high or too low
If camxangle#>90 then camxangle#=90
If camxangle#<-90 then camxangle#=-90
rem Update camera position
`Use newvalues to find a point 200 units *behind the character's position but using camera's yangle value so that user can control camera's rotation around the character object
camx#=NewXValue(Object position x(1),camyangle#,-200)
camy#=NewYValue(Object Position Y(1),camxangle#,-100)
camz#=NewZValue(Object position z(1),camyangle#,-200)
`Curve the camera values
camx#=Curvevalue(camx#,Camera Position X(),5.0)
camy#=Curvevalue(camy#,Camera Position Y(),5.0)
camz#=Curvevalue(camz#,Camera Position Z(),5.0)
`Update camera position
Position Camera camx#,camy#,camz#
`Keep camera pointing at character at all times
Point Camera Object position X(1),Object position Y(1),Object Position Z(1)
rem Simple output for fun
Text 0,440,"Arrow keys to move, RMB to adjust camera position"
SYNC : LOOP
Note that I put the "Point Camera..." command *below* the "Position camera..." command - this is the reason why it was so jerky the first time - you can now remove the curvevalue commands if you want.
Also, if you want the camera to be straight behind/straight above the character object, try this code instead:
rem First we make a character object
Make Object Cube 1,25
rem Now a simple world is made
Make Matrix 1,2500,2500,15,15
rem Start a loop
SYNC ON : DO
rem Allow movement of our character object using the arrowkeys
If Upkey()=1 then Move Object 1,3
If Downkey()=1 Then Move Object 1,-3
If Leftkey()=1 Then yangle#=Wrapvalue(Object Angle Y(1)+3.0)
If Rightkey()=1 Then yangle#=Wrapvalue(Object Angle Y(1)-3.0)
rem Update object's y angle
Yrotate Object 1,yangle#
rem Now we handle the camera
`If user presses right mouse button, alter camera angle value but adding the angle value to the mouse's movement in the x-axis
If mouseclick()=2
camyangle#=Wrapvalue(camyangle#+Mousemovex())
camxangle#=camxangle#+MousemoveY()
Endif
`Apply limits on the camera x angle (i.e. y position) - this way camera is prevented from going up too high or too low
If camxangle#>90 then camxangle#=90
If camxangle#<0 then camxangle#=0
`Here i'm setting the distance so that the camera will be right on top of the character when camera is pointing straight down
`Basically, when the camera is on the ground point straight at the character, the distance should be 200. When it straight above, distance should be 0. Therefore I use this formula to achieve just that
dist#=200-(camxangle#*200/90)
rem Update camera position
`Use newvalues to find a point 200 units *behind the character's position but using camera's yangle value so that user can control camera's rotation around the character object
camx#=NewXValue(Object position x(1),camyangle#,-1*dist#)
camy#=NewYValue(Object Position y(1),camxangle#,-200)
camz#=NewZValue(Object position z(1),camyangle#,-1*dist#)
`Curve the camera values
camx#=Curvevalue(camx#,Camera Position X(),5.0)
camy#=Curvevalue(camy#,Camera Position Y(),5.0)
camz#=Curvevalue(camz#,Camera Position Z(),5.0)
`Update camera position
Position Camera camx#,camy#,camz#
`Keep camera pointing at character at all times
Point Camera Object position X(1),Object position Y(1),Object Position Z(1)
rem Simple output for fun
Text 0,440,"Arrow keys to move, RMB to adjust camera position"
SYNC : LOOP
Hello World Tommorrow