i am having trouble making a script that moves an entity when i click a certain position on the screen. heres what ive got:
////////////////////////////////
#include <pure.c>//this file only contains include acknex + default
////////////////////////////////
BMAP* cursor = "cursor.bmp";
ENTITY*p;
ENTITY*po;
ENTITY*flag;
var moving=0;
////////////////////////////////
function ajus()
{
VECTOR pos1, pos2;
pos1.x = mouse_pos.x;
pos1.y = mouse_pos.y;
pos1.z = 0;
vec_for_screen (pos1, camera);
pos2.x = mouse_pos.x;
pos2.y = mouse_pos.y;
pos2.z = 20000;
vec_for_screen (pos2, camera);
c_trace (pos1.x, pos2.x, IGNORE_PASSABLE);
moving=1;
}
action disker()
{
while(1)
{
vec_set(my.x,target);
wait(1);
}
}
action move()
{
my.pan=0;
VECTOR temp;
var cam_angle = 0;
var turn = 0;
VECTOR temp2;
p=me;
var anim_a;
var anim_b;
while(1)
{
vec_set(temp,target);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
if(moving==0)
{
anim_a += 0.2;
ent_animate(me,"idle",anim_a,ANM_CYCLE);
}
else
{
anim_b += 2;
ent_animate(me,"run",anim_b,ANM_CYCLE);
c_move (my, vector(8*time_step, 0, 0), nullvector, GLIDE);
}
my.tilt=0;
camera.x = my.x - 200 * cos(my.pan);
camera.y = my.y - 200 * sin(my.pan);
camera.z = my.z + 50;
vec_set(temp2.x, my.x);
vec_sub(temp2.x, camera.x);
vec_to_angle(camera.pan, temp2);
wait(1);
}
}
MATERIAL* night =
{
ambient_blue = 50;
ambient_green = 50;
ambient_red = 50;
diffuse_blue = 50;
diffuse_green = 50;
diffuse_red = 50;
specular_blue = 50;
specular_green = 50;
specular_red = 50;
power = 10;
}
function main()
{
fps_max=60;
video_screen=1;
shadow_stencil=3;
mouse_mode=1;
mouse_map=cursor;
level_load("small.hmp");
ENTITY* sky = ent_createlayer("skycube+6.dds", SKY | CUBE | SHOW, 0);
sky.material=night;
on_mouse_left = ajus;
p = ent_create("armor knight.mdl",vector(0,100,20), move);
po = ent_create ("disk.mdl", target, disker);
set (po, TRANSLUCENT | PASSABLE);
set(p,SHADOW);
while (1)
{
vec_set(mouse_pos, mouse_cursor);
wait(1);
}
}