Create a Patrol Bar
Open up your Patrol Bar Object and create an Object Variable called direction
Make it a number variable
Make the number 0
Create a second Object Variable called Speed
Make it a number variable
Make the number 250
Create a new object
Name it Bar
Make sure the height is the same as the PatrolBar
Bring them both in your scene and make sure the Z order has the PatrolBar on top
Open your Bar
Open up Points
Add a Point at the end of your Bar
Name it BarEnd
Go to your events
We are going to change the direction variable so that one event makes the PatrolBar goes right and the other goes left
Condition
PatrolBar Object Variable Value fir Direction is equal to 0
Action
We are going to add force at an angle so that it goes left and right
Object: PatrolBar
Add a force (angle)
Angle: -180 (we are going this so that the bar goes left, remember graphing? Right is positive and left is negative).
Speed: (PatrolBar.Variable(speed))
We are grabbing the object variable "Speed" that we created on the PatrolBar
Create a new event just like the first event but change the variable to 1 and make the angle 0 so the PatrolBar goes right when the variable changes to 1
Now we are going to have the variable "Direction" change when it gets to the X position points we have set in our events
Condition
Object: Patrol Bar
X position
Less Than (we want less than because once the PatrolBar comes to the end of the left side, we want it to switch variables and go right)
Bar.X()
The Bar.X() is the origin in your points
Action
Object: PatrolBar
Change object variable value
Variable: Direction
Set to 0 (zero because we want it going right)
Now we want a second event that has the direction variable 1 make the PatrolBar go left
Condition: PatrolBar
X Position
Greater than Bar.PointX("End")
Remember we created teh End point in our Bar object?
Action
Object: PatrolBar
Change object variable direction and set to 1
So Variable 0 makes the PatrolBar go left (-180 degrees)
Once it gets to X position 0, the variable changes and goes right (0 degrees)
When the PatrolBar gets to the End point we created, the variable switches to 1
And on and on
When you test right now, nothing happens because we haven't added any force to make the PatrolBar move at the start of the scene
We want this to happen always so there will be no condition
Action
Object: PatrolBar
Add a force (angle)
Angle: PatrolBar.Direction (You want to use the "Direction" Variable of PatrolBar to get the bar started)