HI, Shouldn't you use vec_rotate(tempv,camera.pan) then c_trace. I think you are tracing straight down.
Good idea. Maybe c_trace vectors are messed, right...did not look how he calculated the from and to vectors of the trace.
Try this ( just written not tested )
var hitvertex_global = 0; // global var holding last hit vertexnr
/*
// not sure if a terrain sets the YOU pointer when hit by c_trace. if not use something like this ( or hit.entity )
// and simply change "YOU" below to "terrainEnt"
ENTITY* terrainEnt;
action myTerrain_WED(){ // apply2 terrain in WED
terrainEnt = me;
}
*/
action / function whatever(){
...
...
hitvertex_global = 0;
VECTOR _temp;
_temp.x = mouse_pos.x;
_temp.y = mouse_pos.y;
_temp.z = 0;
vec_set (target, _temp);
target.z = 10000;
vec_for_screen (_temp, camera);
vec_for_screen (target, camera);
trace_mode = IGNORE_ME | IGNORE_PASSABLE;
c_trace (_temp, target, trace_mode);
if (HIT_TARGET){ // sure "hit" pointer was set ( =hit something ) ?
hitvertex_global = hit.vertex;
if (hitvertex_global && you){ // vertex? you?
VECTOR _p;
vec_for_vertex (_p, you, hitvertex_global);
ent_create ("example.mdl", _p, NULL);
}
//same as ent_create ("bla.mdl", target, NULL); so theres no need4 vec_for_vertex in my quick example ^^
}
}
Edit:
Besides...
After the c_trace check if you hit something ( entity 4ex ). Dont do:
c_trace ( ... );
you.health -= 10;
may Crash with "empty pointer". Do it like this instead
c_trace ( ... );
if (you) you.health -= 10;
In your case "hit" - may cause "empty pointer" error sometime, if i take a wild guess. ^^
Greets