How to add animation to movement

C

Caroline Messoussa

Guest
Hi there,

I have recently started coding with Gamemaker and am making a top down shooter, kinda like Hotline Miami.
I have been able to find a website:https://www.yoyogames.com/blog/432/buttery-smooth-tech-tips-movement
which gave me tips on a super smoothe code for player movement however I have not found any tutorials inlcuding adding animation to said movements online. This is my code, can anyone help me please?

CREATE EVENT:
//Movement Variables - These is a 1 dimensional array: each direction represents a 90 degress increment
move_speed = 600;
movement_inputs[0] = ord("D"); // 0 degress (right)
movement_inputs[1] = ord("W"); // 90 degress (up)
movement_inputs[2] = ord("A"); // 180 degrees (left)
movement_inputs[3] = ord("S"); // 270 degrfees (down)

STEP EVENT:
// Basic Movement Variables
var seconds_passed = delta_time/1000000; //Gives us number of seconds passed in the frame
var move_speed_this_frame = move_speed*seconds_passed; //Speed times seconds equals 600 pixels per second therefore our player moves 600 pixels per second

//Basic Movement
var move_xinput = 0;
var move_yinput = 0;

for (var i = 0; i < array_length_1d(movement_inputs); i++){
var this_key = movement_inputs;
if keyboard_check(this_key) {
var this_angle = i*90;
move_xinput += lengthdir_x(1, this_angle);
move_yinput += lengthdir_y(1, this_angle);
}
}

var moving = ( point_distance(0,0,move_xinput,move_yinput) > 0 );
if moving {
var move_dir = point_direction(0,0,move_xinput,move_yinput);
move(move_speed_this_frame,move_dir);
}

SCRIPT FOR STEP EVENT:
/// @arg speed
/// @arg direction

var spd = argument0;
var dir = argument1;

var xtarg = x+lengthdir_x(spd,dir);
var ytarg = y+lengthdir_y(spd,dir);

if place_free(xtarg,ytarg) {
x = xtarg;
y = ytarg;
}
else {
var sweep_interval = 10;

for ( var angle = sweep_interval; angle <= 80; angle += sweep_interval) {
for ( var multiplier = -1; multiplier <= 1; multiplier += 2) {
var angle_to_check = dir+angle*multiplier;
xtarg = x+lengthdir_x(spd, angle_to_check);
ytarg = y+lengthdir_y(spd, angle_to_check);
if place_free(xtarg,ytarg) {
x = xtarg;
y = ytarg;
exit;
}
}
}
}

So my movement works very well, I just need to know how to add my player animations to selected movements. Thanks in advance!
 
Top