GameMaker Player doesn't turns left

B

Bonweys

Guest
Hi everyone! My problem consists in my player.
When he moves left, i need that the player turns left after it, but the character always returns to the right.

This is my code:

if (!right_move and !left_move) {
sprite_index = MyPlayer;
image_speed = 0;
}


I tried different options but i couldn't did correct code. Help me please!
 
D

DarthTenebris

Guest
If I'm understanding correctly, you want your player to turn left when walking left and vice versa.
Code:
image_xscale = sign(right_move - left_move);
This assumes your sprite can simply be mirrored to achieve left/right direction, and that the variables right_move and left_move are booleans.

Hope I helped :)
 
B

Bonweys

Guest
I don't quite understand what you mean. But if you about "cancel" code which returns sprite so yeah i don't have second code.
 
B

Bonweys

Guest
If I'm understanding correctly, you want your player to turn left when walking left and vice versa.
Code:
image_xscale = sign(right_move - left_move);
This assumes your sprite can simply be mirrored to achieve left/right direction, and that the variables right_move and left_move are booleans.

Hope I helped :)
Thank you, i'll try it a little bit later!)
 
B

Bonweys

Guest
If I'm understanding correctly, you want your player to turn left when walking left and vice versa.
Code:
image_xscale = sign(right_move - left_move);
This assumes your sprite can simply be mirrored to achieve left/right direction, and that the variables right_move and left_move are booleans.

Hope I helped :)
Yes, you understood correct, but when i put your code in my code, character image just becomes flat. It's looks like this :D
 

TsukaYuriko

☄️
Forum Staff
Moderator
An image_xscale of -1 flips a sprite horizontally. The only way for it to do anything else should be when you're somehow overriding how the sprite is drawn in a Draw event, so we'd have to see that code to tell.
 
B

Bonweys

Guest
I need to code when my player will walk to the left and at the ending of his steps stay on the left, but when i walk to the left and don't press any button, character returns to right side.
So i wanna when player will walk on the any side and when i won't press button, character remained in the direction in which he was walking.

I hope i understandably wrote my idea and you will help me)
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
Then stop trying to set the sprite when neither left nor right are pressed. Your character returns to facing right because you explicitly told it to face right when neither left nor right are pressed. Just set image_speed to 0 and be done.
 
B

Bonweys

Guest
Then stop trying to set the sprite when neither left nor right are pressed. Your character returns to facing right because you explicitly told it to face right when neither left nor right are pressed. Just set image_speed to 0 and be done.
Thank you, but when i did it, "walking animation" just froze (
I attached photo:
 

TsukaYuriko

☄️
Forum Staff
Moderator
Instead of paraphrasing what (you think) your code does and posting screenshots of what it (actually) does, it would probably be easier for everyone involved if you actually post the code.
 
B

Bonweys

Guest
Instead of paraphrasing what (you think) your code does and posting screenshots of what it (actually) does, it would probably be easier for everyone involved if you actually post the code.
Ok, sorry.

My code of return character to the initial position:

if (!right_move and !left_move) {
sprite_index = MyPlayer;
image_speed = 0
}
 

TsukaYuriko

☄️
Forum Staff
Moderator
No need to apologize. :)

That's the exact code you posted in the opening post - that's surely not all the code there is? Please post all relevant code, as the code you just posted has nothing to do with turning left.
 
B

Bonweys

Guest
No need to apologize. :)

That's the exact code you posted in the opening post - that's surely not all the code there is? Please post all relevant code, as the code you just posted has nothing to do with turning left.
This is code how he walk to the left
if (left_move) {
phy_position_x -= 4;
sprite_index = WalkLeft;
image_speed = 1;
}
 
Top