Both objects move parallel to the map.
I tried to use the Lerp function, but I can not make it work. How do I use this function correctly?
Both objects move parallel to the map.
I tried to use the Lerp function, but I can not make it work. How do I use this function correctly?
As the two objects move in parallel and always the same distance, I believe that the simplest solution is to directly second object according to the position of the first, plus an offset distance.
A simplified example follows:
The sp1
object follows the coordinates of the mouse (every tick event):
Set position to (Mouse.X, Mouse.Y)
In the same event, you add an action by changing the position of the
object sp2
for a fixed distance from the position of sp1
(in this example, 150 units in the X
axis):
Set position to (sp1.X + 150, sp1.Y)
The Event sheet looks like this:
Thelerp
functioncalculatesa linear interpolation between 2 points, and can to be
used, for example, to smooth the movement of an object:
lerp(a, b, x)
For the above function call, it returns the value of a + x*(b-a)
.
In the example, if you replace the action with the object sp2
with:
Set position to (lerp(sp1.X, sp1.X + 300, 0.5), sp1.Y)
It will achieve exactly the same effect, however, with a higher processing cost.