J
Jacob Colston
Guest
As the title said I added a script that would update my player sprite based on the position of the mouse. If I had my mouse above the player sprite, the sprite would look up. This script works, however, after adding this script my character stopped conducting the movement animation. I have spent 2 days trying to get my sprite to animate to no avail. I tried everything I could come up with including creating a ton of if statements (for example if character is looking up AND is moving then sprite_index = spr_player_up) but no matter what I could not get it to work.
My end goal is to make it so that the sprite animates in the direction of the mouse when moving (so if the mouse is above the player the sprite would be animated spr_player_up, if below then spr_player_down and so on) Currently the player successfully LOOKS towards the mouse, however, it DOES NOT do the movement animation at all.
Here are my codes:
obj_player create event
obj_player step event
obj_player end animation event
scr_move_state
scr_get_input
My end goal is to make it so that the sprite animates in the direction of the mouse when moving (so if the mouse is above the player the sprite would be animated spr_player_up, if below then spr_player_down and so on) Currently the player successfully LOOKS towards the mouse, however, it DOES NOT do the movement animation at all.
Here are my codes:
obj_player create event
event_inherited();
spd = 4;
hspd = 0;
vspd = 0;
xaxis = 0;
yaxis = 0;
len = 0;
dir = 0;
depth = -10;
scr_get_input();
state = scr_move_state;
/// Create Event - creating the sectors
player_look[5] = spr_player_down;
player_look[6] = spr_player_down;
player_look[7] = spr_player_right;
player_look[0] = spr_player_right;
player_look[1] = spr_player_up;
player_look[2] = spr_player_up;
player_look[3] = spr_player_left;
player_look[4] = spr_player_left;
obj_player step event
/// Move the player in the step event
script_execute(state);
event_inherited();
// where to look
sprite_index = player_look[point_direction(x,y,mouse_x,mouse_y) div 45];
obj_player end animation event
/// change back to move state
if (state == scr_attack_state) {
state = scr_move_state;
}
if (state == scr_attack_state) {
state = scr_move_state;
}
scr_move_state
///scr_move_state
scr_get_input();
image_speed = .5;
/// this line says that if player faces direction the state is to move
if (player_look[0 || 7 || 1 || 2 || 3 || 4 || 5 || 6]){
image_index = 0;
state = scr_move_state;
}
// Dashing
if(DASH && (xaxis!=0 or yaxis!=0)) {
state=scr_dash_state;
alarm[0]=room_speed/6;
}
// Attacking
if (ATTACK){
image_index = 0;
state = scr_attack_state;
}
// Get direction
dir = point_direction(0, 0, xaxis, yaxis);
// Get the length
if (xaxis == 0 and yaxis = 0) {
len = 0;
} else {
len = spd;
}
// Get the hspd and vspd
hspd = lengthdir_x(len, dir);
vspd = lengthdir_y(len, dir);
//Move
phy_position_x += hspd;
phy_position_y += vspd;
scr_get_input
///scr_get_input
MOVELEFT = keyboard_check(ord("A"));
MOVERIGHT = keyboard_check(ord("D"));
MOVEUP = keyboard_check(ord("W"));
MOVEDOWN = keyboard_check(ord("S"));
DASH = mouse_check_button_pressed(mb_right);
ATTACK = mouse_check_button_pressed(mb_left);
// Get the axis
xaxis = (MOVERIGHT - MOVELEFT);
yaxis = (MOVEDOWN - MOVEUP);
// Check for gamepad input
if (gamepad_is_connected(0)) {
gamepad_set_axis_deadzone(0, .35);
xaxis = gamepad_axis_value(0, gp_axislh);
yaxis = gamepad_axis_value(0, gp_axislv);
DASH = gamepad_button_check(0, gp_face1);
ATTACK = gamepad_button_check(0, gp_face3);
}
MOVELEFT = keyboard_check(ord("A"));
MOVERIGHT = keyboard_check(ord("D"));
MOVEUP = keyboard_check(ord("W"));
MOVEDOWN = keyboard_check(ord("S"));
DASH = mouse_check_button_pressed(mb_right);
ATTACK = mouse_check_button_pressed(mb_left);
// Get the axis
xaxis = (MOVERIGHT - MOVELEFT);
yaxis = (MOVEDOWN - MOVEUP);
// Check for gamepad input
if (gamepad_is_connected(0)) {
gamepad_set_axis_deadzone(0, .35);
xaxis = gamepad_axis_value(0, gp_axislh);
yaxis = gamepad_axis_value(0, gp_axislv);
DASH = gamepad_button_check(0, gp_face1);
ATTACK = gamepad_button_check(0, gp_face3);
}