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

GameMaker How do I make my Object face the opposite way of my player

S

Sroft

Guest
Hey noob programmer here self teaching
and I cant figure out how do you make an object face the opposite way of my player
I don't know if I need to post any code here or not so if I do please say so!
Thank you : ^)!
 

samspade

Member
Hey noob programmer here self teaching
and I cant figure out how do you make an object face the opposite way of my player
I don't know if I need to post any code here or not so if I do please say so!
Thank you : ^)!
Do you mean if the player is facing right, the object should face left (regardless of whether the object is to the left or right of the player)? Or that if the player is to the left of the object, the object should face right? It also depends on how you've set other things up, such as the sprite. How you draw things, such as the sprite. Orientation, such as top down or platformer. And so on.

For the first, you simply need to know which way the player is facing. This could be determined in a lot of different ways depending upon how you have set other things up. For example, sign(image_xscale) would work in some situations (e.g. 2D platformer where you use image_xscale to determine facing). Or point_direction(0, 0, hsp, vsp); would work in others (e.g. 2D top-down with full 360 motion).

For the second you need to know the direction to the player. So for example:

Code:
if (instance_exists(obj_player)) {
    dir_to_player = sign(obj_player.x - x);
}
But again, you probably need to be more detailed in what you are looking for and how other things are set up.
 
S

Sroft

Guest
Do you mean if the player is facing right, the object should face left (regardless of whether the object is to the left or right of the player)? Or that if the player is to the left of the object, the object should face right? It also depends on how you've set other things up, such as the sprite. How you draw things, such as the sprite. Orientation, such as top down or platformer. And so on.

For the first, you simply need to know which way the player is facing. This could be determined in a lot of different ways depending upon how you have set other things up. For example, sign(image_xscale) would work in some situations (e.g. 2D platformer where you use image_xscale to determine facing). Or point_direction(0, 0, hsp, vsp); would work in others (e.g. 2D top-down with full 360 motion).

For the second you need to know the direction to the player. So for example:

Code:
if (instance_exists(obj_player)) {
    dir_to_player = sign(obj_player.x - x);
}
But again, you probably need to be more detailed in what you are looking for and how other things are set up.
Thanks a lot for the very detailed reply! I will surely use this info in the future : ^)
sorry for not being detailed but here is the details if you wanna answer
Its a 2D platformer and the sprites are facing to the right( and I think I could have done this myself but I don't get (signs) to well))
anyway I tried the sign(image_xscale) but didn't work out to well (I should also mention that I want the Obj to face the opposite direction from the player at all times)
I managed to make it follow the players direction with
oAmailia_holo.image_xscale = PObject.image_xscale
but not make it oposite
Thanks a lot again!
 
S

Sroft

Guest
oAmailia_holo.image_xscale = -(PObject.image_xscale) ?
Sorry for the late response power went out
Btw i’m dumb never knew you could do that (this is the first thing I am coding though but still no excuse for that easy thing)
I learned a lot from you
Thanks so much!!!
 
Top