#Player not facing the correct way

45 messages · Page 1 of 1 (latest)

gusty violet
#

When trying to implement different directions for my player to face when moving in different directions, the direction my character is facing seems to be opposite of the direction it is moving in when actually testing it, and I was wondering if someone could poit out my mistake.

Here is the code I have:

//move the player
x += xspd;
y += yspd;

//set sprite
if xspd > 0 {face = RIGHT};
if xspd < 0 {face = LEFT};

if yspd > 0 {face = DOWN};
if yspd < 0 {face = UP};
sprite_index = sprite[face];

And then:

sprite[RIGHT] = spr_player_right;
sprite[UP] = spr_player_up;
sprite[LEFT] = spr_player_left;
sprite[DOWN] = spr_player_down;

face = DOWN;

bitter wind
#

The code looks solid and understandable (assuming the top part is the step event and bottom is the create event)

Based on what has been given, I don't see a reason every direction would have the wrong sprite, unless spr_player_right has the character facing left and spr_player_down has the character facing up (I doubt this is the case).

I would need more information to know what was wrong. Shooting in the dark here, some potential issues to look for are having image_angle set to 180, or image_xscale set to a negative value.

gusty violet
#

What information would you need?

bitter wind
#

Have you tried debugging it?
What are the values of face, image_angle, and image_xscale when xspd > 0?

gusty violet
#

I'm not 100% sure as i can't check atm, and I'm also very new at coding, would it be alright if i get back to you later?

bitter wind
#

Yea, take your time. I'm on my way to work atm. Do you know how to debug to see the variables?

gusty violet
#

Uh no, i just started 2 days ago

#

Could you tell me how?

bitter wind
#

I see, no worries. Debug is the bug icon next to play. While you play, try to get your character to move right and pause the game at the same time. Do you remember what the object is called? Something like obj_player?

gusty violet
#

Yeah

bitter wind
#

While the game is paused with your character moving right, look for a "Watches" tab where you can directly view what variables are. Type in the following and verify it's working correctly

  • obj_player.sprite_index == spr_player_right - this should return true or false. Since we are moving right, It should be true
  • obj_player.image_angle - This controls the angle of the object. Default is 0
  • obj_player.image_xscale - This controls how wide the characters is. A negative value means it's flipped. Default is 1
gusty violet
#

Ok, I'll look into it and get back to you when I can, thank you

gusty violet
#

So do i type those in there?

bitter wind
#

Yee. It should give you a value. If they aren't what we expect, then we know something is wrong

gusty violet
#

The last one came back negative, instead of positive

bitter wind
#

Ah! This would explain why your character is facing the opposite direction. Somewhere it must be setting image_xscale to the opposite value. I wonder if this is true for image_yscale as well

gusty violet
#

So where would I go to fix this?

bitter wind
#

You would have to find the line of code that is doing this. Somewhere in your code, you told Gamemaker to set image_xscale to change. That variable never changes from 1 unless you tell it to.

gusty violet
#

I don't remember typing that, would it be alright if i show you all the code ive written so far?

bitter wind
#

Absolutely, feel free.

Try doing CTRl + shift + F, this will pull up a global search box. This might help you find where image_xscale is being changed

gusty violet
#

Ok thank you very much

gusty violet
#

When I did the search, it said 0 results found, and here is all the code ive written.

#

Create:
xspd = 0;
yspd = 0;

move_spd = 1;

sprite[RIGHT] = spr_player_right;
sprite[UP] = spr_player_up;
sprite[LEFT] = spr_player_left;
sprite[DOWN] = spr_player_down;

face = DOWN;

Step:
right_key = keyboard_check(vk_right);
up_key = keyboard_check(vk_up);
left_key = keyboard_check(vk_left);
down_key = keyboard_check(vk_down);

//get xspd and yspd
xspd = (right_key - left_key) * move_spd;
yspd = (down_key - up_key) * move_spd;

//collisions
if place_meeting(x + xspd, y, obj_wall) ==true
{
xspd = 0;
}

 if place_meeting(x, y + yspd, obj_wall) ==true
  {
      yspd = 0;
  }

//move the player
x += xspd;
y += yspd;

//set sprite
if xspd > 0 {face = RIGHT};
if xspd < 0 {face = LEFT};

if yspd > 0 {face = DOWN};
if yspd < 0 {face = UP};
sprite_index = sprite[face];

Scripts:
#macro RIGHT 0
#macro UP 1
#macro LEFT 2
#macro DOWN 3

bitter wind
#

Yea, nothing in here seems to be setting image_xscale to -1.

The only other thing that comes to mind would be the "Variable Definition" section in the object editor. I don't believe those show up in a search.

If that's not it, I am stumped. If you feel comfortable with it, you could export your project and I could take a look after work.

gusty violet
bitter wind
#

Yup, it's not there either.

gusty violet
#

How would i go about experting it? If you dont mind that is

#

*Exporting

bitter wind
#

I believe it's something like File - > Export

gusty violet
#

Yyz or as template?

bitter wind
#

yyz sounds correct

gusty violet
#

Do you want me to send it to your email?

bitter wind
#

Whatever works. I'll dm you

gusty violet
#

Alr

bitter wind
#

I'm taking a look now

#

Found it!

#

I forgot rooms could let you modify this stuff

gusty violet
#

So the room can change the x value and y value in them?

#

Like have everything in the room flipped?

bitter wind
#

Yes. The X I circled is the same thing as image_xscale. Once I set this back to positive 1, it fixed it

bitter wind
gusty violet
#

So if the rooms xscale value is negative 1, does that make everything in that rooms xscale -1 as well?

bitter wind
#

It's not the rooms xscale value (this does not exist), it's the instance of obj_player that you placed in the room.

gusty violet
#

Oh gotcha, i think i understand

#

Thanks for your help