Here's how Id do it...
First of all, establish what you want to do in 2D. You need to get the angle between a player and the mouse, and rotate them to that angle. The atanfull command can be used pretty easily to get this information provided you have two positions.
Here's a demo of it in 2D...
`Create a 2D square character for us to move and rotate.
BOX 0,0,32,32
BOX 10,0,26,10,RGB(000,255,255),RGB(000,255,255),RGB(255,255,000),RGB(255,255,000)
GET IMAGE 1,0,0,32,32
`Set some program parameters to save us time / hassle...
SYNC ON:SYNC RATE 0:AUTOCAM OFF
`Turn our character image into a sprite so we can manipulate it easier
SPRITE 1,SCREEN WIDTH()/2,SCREEN HEIGHT()/2,1
OFFSET SPRITE 1,16,16
`Declare the variables we'll be using
sx# = 0
sy# = 0
mx# = 0
my# = 0
angle# = 0
`Main program loop
DISABLE SYSTEMKEYS:WHILE ESCAPEKEY() = 0
`Update variables
sx# = SPRITE X( 1 )
sy# = SPRITE Y( 1 )
mx# = MOUSEX()
my# = MOUSEY()
`Calculate angle between sprite and mouse
angle# = math_getAngle(mx#,my#,sx#,sy#)
`Rotate the sprite to the calculated angle
ROTATE SPRITE 1, angle#
`Move sprite based on angle and key input
MOVE SPRITE 1, (KEYSTATE(17) - KEYSTATE(31))*0.5
`Refresh the screen
SYNC
`Repeat until the escape key is pressed, then end the program.
ENDWHILE:END
`This function will calculate the angle between two points using
`the atanfull command.
FUNCTION math_getAngle(X1#,Y1#,X2#,Y2#)
angle# = -ATANFULL(X2#-X1#,Y2#-Y1#)
ENDFUNCTION angle#
So now the only problem is getting the player's two-dimensional coordinate on the screen, from their 3D position in the virtual world.
This isn't all that hard either. There's always the OBJECT SCREEN X/Y commands. But those can be inaccurate when the camera isn't directly above the player, and the camera's field of view comes into play.
So the easier option would be to go the other route and get the mouse's 3D location. This can be done with the PICK SCREEN command, which converts 2D coordinates to 3D.
`Set some program parameters to save us time / hassle...
SYNC ON:SYNC RATE 0:AUTOCAM OFF
POSITION CAMERA 0,200,0:POINT CAMERA 0,0,0
`Create a 3D box for our player.
MAKE OBJECT CUBE 1,32
`Create a 3D sphere for reference to our mouse's 3D location.
MAKE OBJECT SPHERE 2,10
`Declare the variables we'll be using
px# = 0
py# = 0
mx# = 0
my# = 0
angle# = 0
`Main program loop
DISABLE SYSTEMKEYS:WHILE ESCAPEKEY() = 0
`Update variables
px# = OBJECT POSITION X( 1 )
py# = OBJECT POSITION Z( 1 )
PICK SCREEN MOUSEX(), MOUSEY(), 200
mx# = GET PICK VECTOR X()
my# = GET PICK VECTOR Z()
`Calculate angle between sprite and mouse
angle# = math_getAngle(px#,py#,mx#,my#)
`Rotate the sprite to the calculated angle
YROTATE OBJECT 1, angle#
`Control the object with the keys
MOVE OBJECT 1, (KEYSTATE(17)-KEYSTATE(31))*0.5
`Orient the sphere to the mouse's position
POSITION OBJECT 2,mx#, 0, my#
`Refresh the screen
SYNC
`Repeat until the escape key is pressed, then end the program.
ENDWHILE:END
`This function will calculate the angle between two points using
`the atanfull command.
FUNCTION math_getAngle(X1#,Y1#,X2#,Y2#)
angle# = ATANFULL(X2#-X1#,Y2#-Y1#)
ENDFUNCTION angle#
That should work. I had to set the atanfull's output to negative in the 2D version because for some reason it was rotating oppositely, not sure why but not too hard of a fix. The 3D version works normally though. The only difficulty is you need to set the pick vector distance to be the distance the camera is from the ground plain. This is where you might want to look into the pick object command, to get this information.
Also, its not too smart to use a sphere for your player when you're trying to see it rotate properly. Id recommend using a cube or a stretched box, and to be really sure I would add a sphere limb or some sort of identifier on the front of the player so you knew it wasn't facing backwards, as you can't really tell that with simple primitives.