How do I make an object go across the screen, turn around, and come back?

Georgeee

Member
Hi there,

So I'm making a game that requires a plane to go across the sky, hit the outside boundary, then turn around and go back the other way and continue that cycle.

I had it working before, using the actions in the images below. Then I changed something in the game that isn't related to the plane, which then caused it to not work anymore and keep bouncing off the boundary wall. If someone could help me solve this issue, that would mean a lot to me!
 

Attachments

Xer0botXer0

Senpai
Code alternative as I haven't invested time in d&d, perhaps someone else knows how.

GML:
if distance_to_point(room_width + xoffset,y) > 1{move_towards_point(room_width + offset,y);}else{x = 0 - xoffset,y);
With a simple if statement..
In other words, if the distance between your plane instance and the x,y coordinares specified(room_width + offset, y) is more than 1 pixel out..
move towards the specified x,y coordinates..
the 'else' part will run once the condition is met.. which sets your plane back to the start.


xoffset you can declare in your create event, I believe in your d&d you're already using an offset of -84 or something.. so you can set xoffset = 84.
Notice we are adding xoffset when checking distance to point and moving towards point.. how ever subtracting it when reseting the plane position.

if you ever want the plane to stop set "speed = 0".
 
Last edited:

Georgeee

Member
Code alternative as I haven't invested time in d&d, perhaps someone else knows how.

GML:
if distance_to_point(room_width + xoffset,y) > 1{move_towards_point(room_width + offset,y);}else{x = 0 - xoffset,y);
With a simple if statement..
In other words, if the distance between your plane instance and the x,y coordinares specified(room_width + offset, y) is more than 1 pixel out..
move towards the specified x,y coordinates..
the 'else' part will run once the condition is met.. which sets your plane back to the start.


xoffset you can declare in your create event, I believe in your d&d you're already using an offset of -84 or something.. so you can set xoffset = 84.
Notice we are adding xoffset when checking distance to point and moving towards point.. how ever subtracting it when reseting the plane position.

if you ever want the plane to stop set "speed = 0".
Okay great! Where would I put this code?
 
Top