KrimzonDestiny
Member
Hey guys. Taking another crack at programming a different project. I always hit a brick wall when it comes to applying trig to my projects. The similar movement to A Link to the Past with a mouse and keyboard. 'W' moves the player toward whatever target is locked on to, and 'S' moves them backward away from them. I want to use 'A' and 'D' to orbit around the target (whether it be an enemy or the mouse) clockwise and counter-clockwise respectively, but and unsure as to where or how to implement that logic. Thanks for your consideration.
Code:
//switch targets between mouse and actor
var targx,targy;
if(global.target<>noone){
targx=global.target.x;
targy=global.target.y;
}else{
targx=mouse_x;
targy=mouse_y;
}
//set direction
var pdir = point_direction(x,y,targx,targy);
// apply walk movement
if( walk_dir == 1 || walk_dir == -1){
//get distance/length
var len = move_spd;
//get xspd and yspd
xspd = lengthdir_x(len, pdir) ;
yspd = lengthdir_y(len, pdir) ;
}
//move player
x += xspd*walk_dir;
y += yspd*walk_dir;