Move object right direction

M

MarkRazdrh

Guest
So, i have just started programming in this game engine and don't really know alot of things atm, i would love an explanation to the solution.

So basically I made click to move sort of movement in my game which works perfectly fine but the only problem is that i dont know how to make it change sprite when clicked on that direction, for an example;
When i click up the object would move up and change sprite to the one that is walking up, hope it makes sense

What i have right now is when i click up i just have basic sprite which is sprite walking down, so object is moving up but sprite is still the basic one which is sprite walking down

Man this is hard to explain... hope everything makes sense, if you dont understand me please type in the comment and I will try to explain it better
 

Yal

šŸ§ *penguin noises*
GMC Elder
One idea is to use angle_difference and compare your movement direction with the four cardinal directions 0, 90, 180 and 270 (right, up, left and down respectively). If the difference is less than 45 degrees, you're moving in that direction.

So, something like this:

Code:
if(abs(angle_difference(direction,0)) <= 45){
  sprite_index = spr_move_right
}
else if(abs(angle_difference(direction,90)) <= 45){
  sprite_index = spr_move_up
}
/*and so on with more else-if statements for the other directions*/
 
M

MarkRazdrh

Guest
One idea is to use angle_difference and compare your movement direction with the four cardinal directions 0, 90, 180 and 270 (right, up, left and down respectively). If the difference is less than 45 degrees, you're moving in that direction.

So, something like this:

Code:
if(abs(angle_difference(direction,0)) <= 45){
  sprite_index = spr_move_right
}
else if(abs(angle_difference(direction,90)) <= 45){
  sprite_index = spr_move_up
}
/*and so on with more else-if statements for the other directions*/
This works perfectly fine! thanks :)
 
Top