leeeerpiiiing is haaard
First timer needs to know that meters/second is something that we will call distance/time thus ds.
A dog will travel from A to B distance = 100 px. A dog goes fast as speed = 50. Thus ds = speed/distance = 50/100.
Lerp is calculated as A + (B-A)*t where t is <0;1>. We can calculate the B-A as dx and dy and use the distance to calculate unit vector that tells us where the dog moves.
– subtract point B and point A dx = x2 - x1 dy = y2 - y1
– distance between A and B points distance = math.sqrt(dx^2 + dy^2)
– dt adjustment unit sd = speed/distance
– unit direction vector dx = dx/distance dy = dy/distance
dt = 0
Now in update i test if dt == 1. When yes, the dog reached point B and is ready to get another point in path.
So in order to get where the dog is from point A towards point B you need to do this:
** local x,y = Math.lerp(self.x1,self.y1,self.x2,self.y2,self.dx,self.dy,self.dt) self.finished = self.dt == 1 self.dt = math.min(self.dt + game.dt*self.sd,1) return x,y **
And the x,y is either the new position or the dog stops when hitting a wall. Thus the doggo goes slowly from A to B no matter if short or long path because he is limited by his speed during the lerp dt addition phase and the lerp really only looks at dt that goes from 0(pointA) to 1(pointB).
Happy bug hunting lol.
LUA game developing for dumbies
Some nice ways of doing the lua game developing .
Status | In development |
Category | Other |
Author | Bastian |
More posts
- roguelike console57 days ago
- android GPS and other sensor for LOVE2D.58 days ago
- screen flickering65 days ago
- doggie game66 days ago
- canvas speedApr 02, 2025
- memory and garbage collectingMar 26, 2025
- object inheritanceMar 19, 2025
- exportingMar 08, 2025
- light and shadeMar 07, 2025
Leave a comment
Log in with itch.io to leave a comment.