The mouse is in 2D space, but you are trying to position an object in 3D space. The calculation is more complex than what you have.
This is an example from Ric. Use the up and down keys to alter the object's Z-Position. It will always follow the mouse position, irrespective of camera filed of view and position.
`2-d to 3-d by Ric.
autocam off
position camera 10,10,0
fov#=60.0
sh#=screen height()
sw#=screen width()
screenaspect#=sh#/sw#
set camera fov fov#
z#=100.0
make object cube 1,2
do
screenx#=(z#-camera position z())*tan(fov#/2.0)/screenaspect#
screeny#=(z#-camera position z())*tan(fov#/2.0)
x#=((2*screenx#*mousex()/sw#)-screenx#+camera position x())
y#=-((2*screeny#*mousey()/sh#)-screeny#)+camera position y()
if upkey()=1 and z#>5 then dec z#,0.2
if downkey()=1 then inc z#,0.2
position object 1,x#,y#,z#
loop
Original Thread -
http://forum.thegamecreators.com/?m=forum_view&t=51704&b=1