Well I made a little mistake. I wrote ent_create in my code instead of ent_createlayer. Ent_create makes an entity in the world, where the player walks too. Ent_createlayer makes an entity on the camera view. Thus independent of where the player walks and rotates, it's position will always be in the screen.

Seen that you did not know what I was talking about, I think you want the first option . My apologies, for I have not tested the code. I just blindly trust on my superb programming skills . So here an improved code:

Code:

function main()
{
level_load("ent_.wmb");
wait(2);

creat();

mouse_mode = 2;
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait (1);
}
}



function mouseTo3D() {
while (1) {
if (mouse_left) {
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.x); //we return the new 3d vector for further use
}
wait(1)
}
}



function follow_mouse() {
while (me) {
vec_set(you.x, mouseTo3D());
wait(1);
}
}



function creat()
{
while (1) //we will always check for user input, every frame
{
if (mouse_left) //left mouse has clicked!
{
you = ent_create("earth.mdl", nullvector, follow_mouse); //create earth.mdl and let it follow the mouse
}
wait(1);
}
}



Last edited by Joozey; 01/11/08 13:26.

Click and join the 3dgs irc community!
Room: #3dgs