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

Facing n direction of moving

In my game a dog is following the player. Currently image_angle = direction. The dog has a four-directional sprite (dogUp, dogDown, dogLeft and dogRight). How can I change the sprite based on the direction of the dog, and how can I make it that the dog only travels left, right, up and down(i.e not diagonally). Thank you for your help!
 

The-any-Key

Member
Try create your own movement code.
Check if the player x is compare to the dog.
Ex if x>dog.x go right until in next grid poa

you can also use mp_grid_path and disable diagonal movement
 

sp202

Member
Code:
dir= radtodeg(arctan2(keyboard_check(vk_up) - keyboard_check(vk_down), keyboard_check(vk_right) - keyboard_check(vk_left)))
direction=floor(dir/90)*90
 
Do you not know how if statements and sprite_index work yet? If you do, then ask yourself when you want your dog's sprite to change to his up sprite in basic English. Then convert it to code.

If you don't know how those two very basic parts of GameMaker work, you should read through the manual and do at least the basic tutorials that come with gamemaker.

What you're asking to do is very basic. With a little bit of initiative and research, you should have no problem getting this done. Try it out and post what you come up with. If you can't figure it out after a few hours, I'll help you a bit more, if nobody else gives you the answer.
 
Top