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

How do I change the direction of an objects sprite that's moving along path?

D

Den

Guest
I thought it could be done with xprevious but it doesn't work, not really sure why it doesn't lol.
Is there any other ways this could be done some how?
 

Fabseven

Member
if your object is already following a path then you have to stop that first and then set a direction and a speed to move in a direction ?
 
D

Den

Guest
if your object is already following a path then you have to stop that first and then set a direction and a speed to move in a direction ?
sorry I meant to put how to make an objects sprite face the correct way when on a path
 

Alexx

Member
Use the following in the Step Event:

Code:
image_angle=direction;
Ensure your default image is pointing right.

This is a very basic method, it's possible to improve upon this depending on exactly you want it to do.
 
Last edited:
D

Den

Guest
Use the following in the Step Event:
Cheers man but the only issue with this is when the enemy is moving left it flips the sprite upside down because direction value becomes 180 lol
 
G

Gillen82

Guest
Try using image_xscale. If the characther is moving left image_xscale = 1. if character is moving right, image_xscale = -1. This might work!!

This should go into the step event of the object
 
G

Gillen82

Guest
image_xscale should work. Go into the step event and try the following --
if ( speed > 0 ) { image_xscale = 1 }
if ( speed < 0 ) { image_xscale = -1 }
 
G

Gillen82

Guest
Can you copy and paste the code you currently have for the object?
 
D

Den

Guest
Can you copy and paste the code you currently have for the object?
Information about object: obj_police_man
Sprite: spr_police_guy
Solid: false
Visible: true
Depth: -2
Persistent: false
Parent: Enemy_Parent
Children:
Mask:
No Physics Object
Create Event:
execute code:

///Initiate The Enemy's Vars
event_inherited();

//Start the patrol
path_start(Patrol_path, path_spd, path_action_reverse, true);

Step Event:
execute code:

///Initiate The Step Event
event_inherited();

//Controlled check
if(controlled == true) {
state = controlled_state;
}



Other Event: End Of Path:
execute code:

///End of Path Code

path_spd = path_speed;
path_speed = 0;

alarm[PATROL] = room_speed*irandom_range(4,6);
 
N

Never Mind

Guest
Uhmmm... read that carefully:
Code:
if ( speed > 0 ) { image_xscale = 1 }
if ( speed < 0 ) { image_xscale = -1 }
I doubt a path is ever going to set speed to a negative value.

You'll want to use hspeed! (or change your conditionals to use direction)
 
  • Like
Reactions: Den
G

Gillen82

Guest
OK...It was tricky enough (as I'm no genius by any stretch)....but...I got a solution that works

///Create Event Code

//Speed of player
hspd = 2;

//Get total lenght of path
path_len = path_get_length(path_patrol);

//Calculate distance to travel along path before truning
dis_to_turn = path_len / (hspd*2);

//Turn state
turn_timer = dis_to_turn;

//Initiate path
path_start(path_patrol, hspd, path_action_reverse, true);


///Step Event Code

//Minus from turn_timer
turn_timer -= 1;

//When turn_timer reaches zero or below
if( turn_timer <= 0 ){

//Flip image xscale to opposite of current state
image_xscale *= -1;

//Reset turn_timer
turn_timer = dis_to_turn;
}

Hope this helps!!
 
Last edited by a moderator:

xDGameStudios

GameMaker Staff
GameMaker Dev.
it doesn't work with xprevious because of the time it gets updated.... try with xprevious... and put the code in the begin step (I think it is here the right place) or the end step.
 

FrostyCat

Redemption Seeker
You can approximate the previous x position with:
Code:
path_get_x(path_index, path_position-path_speed/path_get_length(path_index))
 
Top