C
CleanFF
Guest
So I am new with GMS and I am working on some player movement. I have used a premade sprite sheet for a place holder and have used multiple sprites for a walk animation. I did some tinkering around and I was able to get it working properly (ie when the user holds "A" the sprite moves left with a walking animation).
After doing this, I wanted the player object to move around with WASD and look towards the cursor, similar to a twin stick shooter. I was able to figure out how to get the sprite look in the direction of the cursor while moving, however I cannot get the sprite animations to work properly. As of right now, when the player object is not moving, the sprite is idle but looks in the direction of the cursor. When the player object moves, it looks as though that the sprite only goes to the first image in the sprite walk animation.
Can anyone assist me on how I can play the full sprite animation when moving?
Here is the code I've written in the Step Event:
direction = point_direction(x, y, mouse_x, mouse_y);
//Look towards mouse
var playerAngle;
playerAngle = point_direction(mouse_x,mouse_y,obj_player.x,obj_player.y);
var downAngle = (playerAngle > 45) and (playerAngle < 135);
var rightAngle = (playerAngle > 135) and (playerAngle < 225);
var upAngle = (playerAngle > 225) and (playerAngle < 315);
var leftAngle = (playerAngle > 315) or (playerAngle < 45);
look = (downAngle or rightAngle or upAngle or leftAngle)
var up = keyboard_check(ord("W"));
var down = keyboard_check(ord("S"));
var left = keyboard_check(ord("A"));
var right = keyboard_check(ord("D"));
move = (up or down or left or right)
if downAngle {
sprite_index = spr_playerDownIdle;
if move {
sprite_index = spr_playerDownWalk;
}
}
if rightAngle {
sprite_index = spr_playerRightIdle;
if move {
sprite_index = spr_playerRightWalk;
}
}
if upAngle {
sprite_index = spr_playerUPiIdle;
if move {
sprite_index = spr_playerUPWalk;
}
}
if leftAngle {
sprite_index = spr_playerLeftIdle;
if move {
sprite_index = spr_playerLeftWalk;
}
}
/// MOVEMENT
var up = keyboard_check(ord("W"));
var down = keyboard_check(ord("S"));
var left = keyboard_check(ord("A"));
var right = keyboard_check(ord("D"));
if up {
y += -1;
}
if down {
y += 1;
}
if left {
x += -1;
}
if right {
x += 1;
}
if move {
image_speed += 0;
image_index += 0;
}
I know the code may be messy or whatever, I have tinkered with it for hours to no avail. Please help!
After doing this, I wanted the player object to move around with WASD and look towards the cursor, similar to a twin stick shooter. I was able to figure out how to get the sprite look in the direction of the cursor while moving, however I cannot get the sprite animations to work properly. As of right now, when the player object is not moving, the sprite is idle but looks in the direction of the cursor. When the player object moves, it looks as though that the sprite only goes to the first image in the sprite walk animation.
Can anyone assist me on how I can play the full sprite animation when moving?
Here is the code I've written in the Step Event:
direction = point_direction(x, y, mouse_x, mouse_y);
//Look towards mouse
var playerAngle;
playerAngle = point_direction(mouse_x,mouse_y,obj_player.x,obj_player.y);
var downAngle = (playerAngle > 45) and (playerAngle < 135);
var rightAngle = (playerAngle > 135) and (playerAngle < 225);
var upAngle = (playerAngle > 225) and (playerAngle < 315);
var leftAngle = (playerAngle > 315) or (playerAngle < 45);
look = (downAngle or rightAngle or upAngle or leftAngle)
var up = keyboard_check(ord("W"));
var down = keyboard_check(ord("S"));
var left = keyboard_check(ord("A"));
var right = keyboard_check(ord("D"));
move = (up or down or left or right)
if downAngle {
sprite_index = spr_playerDownIdle;
if move {
sprite_index = spr_playerDownWalk;
}
}
if rightAngle {
sprite_index = spr_playerRightIdle;
if move {
sprite_index = spr_playerRightWalk;
}
}
if upAngle {
sprite_index = spr_playerUPiIdle;
if move {
sprite_index = spr_playerUPWalk;
}
}
if leftAngle {
sprite_index = spr_playerLeftIdle;
if move {
sprite_index = spr_playerLeftWalk;
}
}
/// MOVEMENT
var up = keyboard_check(ord("W"));
var down = keyboard_check(ord("S"));
var left = keyboard_check(ord("A"));
var right = keyboard_check(ord("D"));
if up {
y += -1;
}
if down {
y += 1;
}
if left {
x += -1;
}
if right {
x += 1;
}
if move {
image_speed += 0;
image_index += 0;
}
I know the code may be messy or whatever, I have tinkered with it for hours to no avail. Please help!