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

Windows Translating image_angle into a direction to travel into

J

Jdown79

Guest
Hey all,
I've done as much research as i can into this issue, but all it shows is the complete opposite, image_angle facing movement direction
I want the polar opposite, I want to move in a straight path according to the image_angle
if someone could link me to a page showing this, or even show me an example I can learn from, that'd be fantastic
 
  • Wow
Reactions: Mut

Roderick

Member
image_angle is just the direction that your speite is facing. It has nothing to do with movement.

If you're using the built in movement functions, direction controls the direction that you're moving.

To make them match, just put

Code:
direction = image_angle;
in an appropriate step event.

Make sure that your sprite is facing to the right when you create it! image_angle and direction both use the right facing (east, if you prefer) as the 0 angle. Creating a sprite that doesn't face right will make image_angle and direction not sync properly.
 

Mick

Member
If you use the built in variables for moving, then this is very simple, you just need to set direction = image_angle and speed to the speed you want.

(Posted the same time as Roderick, hence the redundancy)
 
J

Jdown79

Guest
so if I define
Code:
direction = image_angle
then to move towards that direction,
Code:
if keyboard_check(ord('W'))
    {
        direction +=5
    }
correct? because this loadout isn't working as such.
to recap, I want to move forward in the direction the image is facing.
Yes, my sprites are facing right by default
Thanks guys
 
A

Azure Spectre

Guest
so if I define
Code:
direction = image_angle
then to move towards that direction,
Code:
if keyboard_check(ord('W'))
    {
        direction +=5
    }
correct? because this loadout isn't working as such.
to recap, I want to move forward in the direction the image is facing.
Yes, my sprites are facing right by default
Thanks guys
You would want to increase speed, not direction. Increasing image_angle and/or direction would turn you counter clockwise.
 
J

Jdown79

Guest
You would want to increase speed, not direction. Increasing image_angle and/or direction would turn you counter clockwise.
Ah, as it would. What would be the simplest way of moving in the "image_angle" direction?
 
A

Aura

Guest
You would simply set direction to image_angle and give the instance some speed? What issues are facing with that approach?
 
A

Azure Spectre

Guest
Ah, as it would. What would be the simplest way of moving in the "image_angle" direction?
There are hundreds of ways to go about player movement depending on the sort of game you'd like to make, bet here's a quick dirty one that should let you move a thing around.
Code:
direction=point_direction(x,y,mouse_x,mouse_y);
image_angle=direction;

speed=(keyboard_check(ord('W'))-keyboard_check(ord('S')))*5;
or keyboard controls:
Code:
direction+=(keyboard_check(ord('A'))-keyboard_check(ord('D')))*5;
image_angle=direction;
speed=(keyboard_check(ord('W'))-keyboard_check(ord('S')))*5;
 
J

Jdown79

Guest
direction+=(keyboard_check(ord('A'))-keyboard_check(ord('D')))*5;
image_angle=direction;
speed=(keyboard_check(ord('W'))-keyboard_check(ord('S')))*5;
@Azure Spectre, That snippet is the correct outcome I'm after. is there any chance you could break it down for a novice's understanding? I'm just not understanding how the - functions work, as well as the speed variable supposedly undefined.
Thanks again
 
A

Azure Spectre

Guest
@Azure Spectre, That snippet is the correct outcome I'm after. is there any chance you could break it down for a novice's understanding? I'm just not understanding how the - functions work, as well as the speed variable supposedly undefined.
Thanks again
Sure, no problem.

So the "keyboard_check" function returns false(0) or true(1) depending on whether or not the key defined is pressed down. The "-" symbol is just normal subtraction. So for speed, I'm asking for "forward key - backward key" and then multiplying by 5. So you can get 5, 0, or -5 depending on the keys pressed.

"speed" is built in to Game Maker, just as direction and image angle are.

Hopefully this explanation is clear enough. :p
 
Top