How do i move an object from point A to B in a linear fashion in x amount of time rather than speed without 3rd party plugins?
Figured it out.
totalTime = 3
if currentJourneyTime < totalTime
add dt to currentJourneyTime
lerp(startX, endX, currentJourneyTime/totalTime)
determine the vectorx, by doing curent x - target x
determine the vectory, by doing curent y - target y
on every tick
set x to self.x + vectorx * self.timevariable * deltatime
set y to self.y + vectory * self.timevariable * deltatime
Develop games in your browser. Powerful, performant & highly capable.
Intersting solution, thank you.
However i prefer my method as i'm able to easily define the movement state by checking currentJourneyTime without any distance checks.
If currentJourneyTime < totalTime then objects moving, else objects reached destination.
Depends on what the application is.
Your movement will not be linear if your target moves, it will be homing and accelerate/decelerate to be able to hit the target at the 3 second mark no matter what it could even go backwards if the target gets closer, since you're not defining target as self.target