• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Question: Added animations into my movement code and now my character refuses to move left or right?

K

Kaizer_White

Guest
SOLVED______________SOLVED______________SOLVED__________SOLVED________

Hi...

I'm still in the process of learning GML so I get stuck often. Please bear with me. I just added my character animations and now my character doesn't want to move left or right. he just jumps. Any ideas?

CODE:

/// move_state

// Movement, Collision and Gravity

// Instance Variables

var up = (keyboard_check (ord ("W")))
var left = (keyboard_check (ord ("A")))
var down = (keyboard_check (ord ("S")))
var right = (keyboard_check (ord ("D")))
var space = (keyboard_check (vk_space))
var space_released = (keyboard_check_released (vk_space))

// Gravity

if (!place_meeting (x, y + 1, obj_wall)) {
vspd += grav;
sprite_index = spr_player_jump
image_speed = 0
image_index = (vspd > 0)
if (space_released and vspd < -6) {
vspd = -6
}
} else {
vspd = 0;

// Jumping Code

if (space) {
vspd = -16
}
if (hspd == 0) {
sprite_index = spr_player_idle
image_speed = .25
} else {
sprite_index = spr_player_run
image_speed = .25
}
}

// Movement

if (right) {
hspd = spd
}

if (left) {
hspd = -spd
}

if (hspd !=0) {
image_xscale = sign(hspd);
}

// Friction

if (!right and !left) {
hspd = 0;
}
 
Last edited by a moderator:
D

DyingSilence

Guest
Here's the idea:

Your character only changes sides on keypress, there's no movement code. Add something like:

x+=spd;

Somewhere in the lower parts of code (you need to calculate spd first).
 
K

Kaizer_White

Guest
Here's the idea:

Your character only changes sides on keypress, there's no movement code. Add something like:

x+=spd;

Somewhere in the lower parts of code (you need to calculate spd first).

The character moved before I put in the animations normally...

I tried putting in the x+=spd and it didn't work...
 
D

DyingSilence

Guest
In don't trust that "and" at the last condition. Try && instead.
 
K

Kaizer_White

Guest
You should be putting x+=hspd not spd.
You're changing the horizontal coordinates.

Also, make sure you have specified the spd variable to be greater than 0 in the create event.
if i do that it doesn't work either. To be honest I think it broke it even more 'cos before the character at least turned around. Wit this it doesn't even respond to the key presses.

Thanks anyways tho.
 
K

Kaizer_White

Guest
when I separated the the movement animations and the jump animations, only the movement animations worked.

// Gravity

if (!place_meeting (x, y + 1, obj_wall)) {
vspd += grav;
sprite_index = spr_player_jump
image_speed = 0
image_index = (vspd < 0)
if (space_released and vspd < -6) {
vspd = -6
}
} else {
vspd = 0;

// Jumping Code

if (space) {
vspd = -16
}
}
if (hspd == 0) {
sprite_index = spr_player_idle
image_speed = .25
} else {
sprite_index = spr_player_run
image_speed = .5
}

^Like That^ the jumping animation stopped working... Any ideas anyone?
 

Roderick

Member
Look at the origins and collision masks for each of your sprites. Remember that when you change from one sprite to another, the origin is placed at the x and y coordinates of the object, where the previous sprite's origin was.

I'd be willing to bet that when you change animations, the new bounding box is overlapping with something it wasn't before, causing a collision and preventing movement.
 
K

Kaizer_White

Guest
Look at the origins and collision masks for each of your sprites. Remember that when you change from one sprite to another, the origin is placed at the x and y coordinates of the object, where the previous sprite's origin was.

I'd be willing to bet that when you change animations, the new bounding box is overlapping with something it wasn't before, causing a collision and preventing movement.
All the collision masks for the character are more or less the same... and point of origin are all the same on all the different animations..

I'll try play with that though and see what i come up with.


EDIT: I created a collision mask for the player and everything started working fine... LOL you were right!
 
Last edited by a moderator:
Top