Someone asked about this in User Requests, so I'm posting it here as well for everyone. This version should be easy enough to just drop into your project.



Code:

///terrainPointer
///A.Russell 2007/1
///Maintains an entity at the position under the mouse pointer
///Ideal for point and click games
///
///View should be named "camera" for this to work un-edited,
///which is the default view name
///
///Now if someone can just make a projection shader that works
///with it, that would be ace.
///If you do, or if you have one please PM me on Conitec Forums

action terrainPointer()
{
var inView;
var traceTarget[3];
var distFromCamera;


my.push = 50; //trace through objects with lower push value,
//for example, you might want to ignore trees, rocks and
//anything else that gets in the way of the terrain/ level surface




//Set initial position
mouse_pos.x = screen_size/2;
mouse_pos.y = screen_size/2;

//This is the offset the pointer's hot spot
mouse_spot.x = 9;
mouse_spot.y = 1;


//Make the engine mouse pointer visible
//Set to 0 to make invisible
mouse_mode=1;


while(1) //You might want to put a better condition than this
{
//Move the mouse depending on whether it is fullscreen or not
//I find this method works pretty well for me
if(video_screen == 1) //If fullscreen
{
MOUSE_POS.X += mouse_force.x*60*time;
MOUSE_POS.Y -= mouse_force.y*60*time;
}else //If not fullscreen
{
mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;
}

//Find where that is in 3d co-ordinates
vec_set(temp, mouse_pos);
temp.z = 50;
inView = vec_for_screen(temp, camera);


//If in view, trace from that position until we hit something and put the pointer there.
if(inView)
{
//Do the vector calculations
//to find the direction for the trace.
vec_set(traceTarget, mouse_pos);
traceTarget.z= 5000; //trace up to 5000 quants from view
vec_for_screen(traceTarget, camera);


//Now we have the direction, do the trace
distFromCamera = c_trace(temp, traceTarget,IGNORE_PASSABLE|IGNORE_PASSENTS|IGNORE_PUSH);
//distanceFrom Camera hasn't been used here, but you might find a use for it
//in your project


//Now you can update the position of the pointer model
vec_set(my.x, target); //Target is the position where the ray hits
//the surface of any obsticle it may have hit

//Position it a little bit above the surface
//You could change this to be in front or between
//the player and the intersection point
//depending on your needs
//Projecting an image onto the terrain would be even
//better if anyone can help with this
pointerMDL.z+=10;

}


wait(1);

}
}



Last edited by A.Russell; 01/10/07 16:50.