Posted By: tompo
click and go script - 04/17/07 13:31
Attach my_player action to the player in WED and enjoy 
http://www.youtube.com/watch?v=nWg2ltVMxwU
Code:

http://www.youtube.com/watch?v=nWg2ltVMxwU
Code:
/////////////////////////////////////////////////////////////////////////////
// script for isometric view game //
// with using template model (f.e. warlock.mdl) //
// to moving player with mouse click //
// and changing camera zoom with mouse wheel //
/////////// free to use and free to enjoy :) ////////////////
// TomPo // sorry for terrible Englilsh;) // 16.04.2007 //
/////////////////////////////////////////////////////////////////////////////
entity* player;
var camera_dist[3] = -400,0,600; //distance from camera to player
var distance_to_target; //nothing to explain
var move_position[3]; //move vector
var my_target[3]; //target vertor
var vecTo[3]; var vecFrom[3];
define _speed, skill1; //moving spped
define _moving, skill2; //if the player should move
define anim_speed, skill3; //animating speed
bmap arrow ="arrow_blue.pcx";
IFNDEF MSG_DEFS;
FONT digit_font,<digfont.pcx>,12,16; //template digit .pcx
ENDIF;
panel helper //shows usefuls parameters
{
digits = 20, 20, 3, digit_font, 1,player._moving; //has the player the target to move or not
digits = 20, 40, 3, digit_font, 1,distance_to_target; // you know
digits = 20, 60, 3, digit_font, 1,camera_dist.z; // camera height
flags REFRESH,visible;
}
Function get_target()
{
while(mouse_left == 1)
{
vecFrom.X = MOUSE_POS.X;
vecFrom.Y = MOUSE_POS.Y;
vecFrom.Z = 1;//close point
vec_set(vecTo,vecFrom);
vec_for_screen(vecFrom,CAMERA);
vecTo.Z = 10000;
vec_for_screen(vecTo,CAMERA);//far point
trace(vecFrom,vecTo);//trace a line between the two points
vec_set(my_target,target); //put invisible point on the gorund where you clicked on
player._moving = 1;//I have to move
player.tilt = 0;//keep player straight
wait(1);
}
}
function player_move()
{
while(1)
{
if(player._moving == 1) //if I have to move...
{
distance_to_target = vec_dist(player.x,my_target.x);//calculate distance to target
if(distance_to_target > 45)//if target is far far far away...
{
vec_set(temp,my_target.x);//keep target
vec_sub(temp,player.x); //check my position
vec_to_angle(player.pan,temp);// turn to target
my._speed = 10; //how fast player goes
animate_walk(); //animate player
}
if(distance_to_target <= 45)//if target is close
{
player._moving = 0;//I have not to move
my._speed = 0;//stay
}
}
if(player._moving == 0) //if I have not to move...
{
my._speed = 0;//stay
animate_stand();//animate standing like breathing or something
}
my.tilt = 0;//always stay straight
vec_set(temp,my.X);//check my position
temp.Z -= 1000;//check where the floor is
trace_mode=IGNORE_ME+IGNORE_MODELS+ignore_passable + USE_BOX;
result = trace (my.x, temp);
my.z -= result; //keep me on the ground and move me
c_move(me,vector(my._speed *time_step,0,0),nullvector,GLIDE | ACTIVATE_TRIGGER | IGNORE_SPRITES | IGNORE_PASSENTS | use_box);
wait(1);
}
}
function animate_walk
{
my.anim_speed += 10 * time_step; //add frames
ent_animate(me,NULL,0,0); //reset bones
ent_animate(me,"walk",my.anim_speed,anm_cycle); //animate walk with cyclic
}
function animate_stand
{
my.anim_speed += 3 * time_step;
ent_animate(me,NULL,0,0);
ent_animate(me,"stand",my.anim_speed,anm_cycle);
}
function move_camera
{
while(player != 0)
{
MOUSE_POS.X = POINTER.X; MOUSE_POS.Y = POINTER.Y;
camera_dist.z -= mickey.z * time_step; //change camera height with mosue wheel
camera_dist.z = clamp(camera_dist.z,player.max_z,600); //not to height and not hit the ground
vec_set(temp,player.pos); //check player position
vec_add(TEMP,camera_dist); //add to player position camera distance
vec_set(camera.pos,temp); //place camera at the correct position
vec_set(temp,player.x); //again check player position
vec_sub(temp,camera.x); //check camera position
vec_to_angle(camera.pan,temp); //turn camera to the player
wait(1);
}
}
action my_player
{
player = me;
video_switch (0,0,1);//switch to fullscreen
MY.FAT = OFF;
MY.NARROW = ON;
mouse_mode = 2;//make cursor visible and moving
mouse_map = arrow;//mouse bmap
mouse_range = 10000;//mouse range from camera
player_move();
move_camera();
}
view camera
{
layer = 0;
arc = 60;
aspect = 1;
ambient = 80;
flags = visible;
}
On_mouse_left get_target;
