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

[solved]making Objects still when aligned with player

W

Wild_West

Guest
I hadn't noticed i had this problem until messing about with level design, but I have these 2 standard enemies that chase after the player, and I only ever did it for a sideways check, since that's all I needed.
But I tried putting my player underneath a platform with the chasing enemies on top and stood directly over the player. They only chase when the player's x is greater than or less than their own x value, and animate and change their x scale when doing so of course, but when they aren't chasing I want them to not animate or move at all.
Problem is this doesn't happen, the enemies stay stationary like hey should but they keep flipping their x scale back and forth like their trying to wait for the next direction to move in even though the player is standing still.

I've tried using this to keep their image still but it doesn't work so I think I'm still misunderstanding how 2 object's x and y values are calculated in relation to each other?

if(x < player_parent_object.x)
{
if(place_free(x + 50, y) )
hspeed = 7;
image_speed = 0.2;
image_xscale = 1;
}
if(x > player_parent_object.x)
{
if(place_free(x - 50, y) )
hspeed = -7;
image_speed = 0.2;
image_xscale = -1;
}
if(x == player_parent_object.x)
{
hspeed = 0;
image_speed = 0;
}
 

Phil Strahl

Member
Have you tried rounding the values to integers? E.g.
Code:
if(round(x) < round(player_parent_object.x))
// ...

if(round(x) > round(player_parent_object.x))
// ...

if(round(x) == round(player_parent_object.x))
// ...
 
W

Wild_West

Guest
Have you tried rounding the values to integers? E.g.
Code:
if(round(x) < round(player_parent_object.x))
// ...

if(round(x) > round(player_parent_object.x))
// ...

if(round(x) == round(player_parent_object.x))
// ...
Only when I drew the values on screen but I'll apply it to the actual code too
 
W

Wild_West

Guest
Have you tried rounding the values to integers? E.g.
Code:
if(round(x) < round(player_parent_object.x))
// ...

if(round(x) > round(player_parent_object.x))
// ...

if(round(x) == round(player_parent_object.x))
// ...
Well the rounding method didn't work but I was able to get the result I wanted using a condition for the Y axis instead.
 
Top