Here is full code :
#include <default.c>
////////////////////////////////////////////
ENTITY* earth;
var vect[3];
function main()
{
level_load("ent_.wmb");
wait(2);
mouse_mode = 2;
creat();
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait (1);
}
}
var mouse_click[3];
function mouseTo3D()
{
if (mouse_left)
{
vec_set (mouse_click, mouse_dir3d);
vec_normalize(mouse_click, 4000);
vec_add (mouse_click, camera.x);
c_trace (camera.x, mouse_click, IGNORE_MODELS);
return(target.x); //we return the new 3d vector for further use
}
}
}
function follow_mouse()
{
vect=mouseTo3D();
while (me)
{
//while (earth == NULL) { wait(1); }
vec_set(earth.x,vect);
wait(1);
}
}
function creat()
{
while (1) //we will always check for user input, every frame
{
if (mouse_left) //left mouse has clicked!
{
nyou = ent_create("earth.mdl", nullvector, follow_mouse);
while (mouse_left) {wait(1);}
}
wait(1);
}
}
I declare var vect[3];
Thank you very much.