• 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!

Movement / Animation Code Issue

A

atxgamedesigner

Guest
Hello -

I decided to mess around with a little top-down prototype this evening.
For some reason I cant figure out why this movement script isn't working as expected.
Ha - it's past my bed time though, so I'm probably just not thinking critically enough on this...
But still - figured I'd post on here to see what you guys have to say.

Code:
if (keyboard_check(ord('W'))) {
    y -= 3;
    image_angle = 90;
    sprite_index = spr_Survivor_Walk;
    obj_Feet.sprite_index = spr_Feet_Walk;
}
if (keyboard_check(ord('S'))) {
    y += 3;
    image_angle = 270;
    sprite_index = spr_Survivor_Walk;
    obj_Feet.sprite_index = spr_Feet_Walk;
}
if (keyboard_check(ord('A'))) {
    x -= 3;
    image_angle = 180;
    sprite_index = spr_Survivor_Walk;
    obj_Feet.sprite_index = spr_Feet_Walk;
}
if (keyboard_check(ord('D'))) {
    x += 3;
    image_angle = 0;
    sprite_index = spr_Survivor_Walk;
    obj_Feet.sprite_index = spr_Feet_Walk;
}
else {
    sprite_index = spr_Survivor_Idle;
    obj_Feet.sprite_index = spr_Feet_Idle;
}
Basically, I have 2 objects - an "upper body" and a "lower body" - (that way I could control the feet separately).

When using the W, A, S and D keys, the upper body moves and faces in the correct direction.
Unfortunately, the upper and lower body animations only work when pressing the D key.

So, just to recap -
W = moving up, but with idle upper and lower body animations.
A = moving left, but with idle upper and lower body animations.
S = moving down, but with idle upper and lower body animations.
D = works as expected...

Can't figure this one out.
 

Mick

Member
Unfortunately, the upper and lower body animations only work when pressing the D key.
Where do you set your image_speed? There is nothing in the code you posted that defines anything about animation.

You also want to set obj_Feet.image_angle .
 
D

Dudeidu

Guest
You need to use "else if", ex:
if (condition){
}
else if (another condition){
}
else if (yet another condition){
}
else (on the last one){
}
 
A

atxgamedesigner

Guest
WitchMaster -
The image_speed for the animation is set in the create event for each object.
The image_angle of obj_Feet is set in that object's step event - every step I tell that object to follow obj_Survivor, as well as match the image_angle of obj_Survivor.

Dudeidu -
I feel super dumb, lol. That solved the problem.
This is what I get for staying up past my bed time goofing off hahaha.
 
Top