Good evening everyone,
I want to create an entity that is always at the same position (in world_coordinates) that the mouse cursor (in mouse coords of course) is at (only x and y coords, z-coords don't matter). In order to do that one needs to convert the mouse position to world coordinates (vec_for_screen), so that the engine knows where to place the model.
Here is the code:
function mouse_item()
{
MouseItem = me;
set(my, PASSABLE);
var ex;
var ey;
var ez;
while(1)
{
ex = mouse_pos.x;
ey = mouse_pos.y;
ez = 0;
vec_for_screen(vector(ex, ey, ez), camera);
ent_create("ring.bmp",vector(ex,ey,ez), ring);
wait(1);
}
}
The code constantly creates small rings at the calculated coordinates so that one can see where exactly vec_for_screen points to.
Now here is my problem. The code behaves really strange.
First of all the rings are not created at the mouse_cursor's position but with a offset (x and y offset).
Second, they are created at positions inverted to the mouse's movement.
And third, moving the view does not affect where the rings are created (the view is fixed on top of the player and you can move the player around thus changing the view's position).
There are a quiet some threads about vec_for_screen and vec_to_screen... but really, I don't see what went wrong in the above script.
To avoid this problem I measured the window's size in pixels, calculated the zero-vector (resolution / 2, not really but works) or the middle of the screen and then calculated the vector from there to the mouse. Now one can use the angle from 0,0 to mouse x,y... but that is not really a solution since it creates a whole bunch of other problems.
c_trace works too... but that too is what you would call a "dirty trick" I guess.
Sorry if I overlooked something in the manual or just wrote a bad syntax.
Thanks for taking a look at it!