My mistake (again), replace the mouseTo3D() with the following code:
Code:
var mouse_click[3];
function mouseTo3D() {
vec_set (mouse_click, mouse_dir3d); //get direction vector from mouse to world
vec_normalize(mouse_click, 4000); //give it a large distance for tracing
vec_add (mouse_click, camera.x); //calculate from camera position
c_trace (camera.x, mouse_click, IGNORE_MODELS); //trace from camera to clicked position (= mouse position + 4000 in depth)
return(target); //we return the new 3d vector for further use
}
And if you would click the left mouse now, alot of entities are created. To prevent that, replace and type:
Code:
if (mouse_left) //left mouse has clicked!
{
you = ent_create("earth.mdl", nullvector, follow_mouse); //create earth.mdl and let it follow the mouse
while (mouse_left) {wait(1);}
}