Replies: 3 comments 5 replies
-
If user already provide obj.move(xVel, yVel);
// then make sure didn't go pass vec2(xPos, yPos) So if |
Beta Was this translation helpful? Give feedback.
-
I would say that the speed is always pointing to the point, that I calculate if it should go forward or backwards xDir;
yDir;
if(obj.pos.x > xPos) xDir = -1;
else xDir = 1;
if(obj.pos.y > yPos) yDir = -1;
else yDir = 1;
action(() => {
if(obj.pos.x.toFixed() != xPos) {
obj.move(xVel * xDir, 0)
}
if(obj.pos.y.toFixed() != yPos) {
obj.move(0, yVel * yDir)
}
}) The example is to be better understood, that code would not work so much if someone wants the object to move to a position in float |
Beta Was this translation helpful? Give feedback.
-
Added the function in style of // speed is in pixels per second, if not given will teleport instantly
moveTo(dest: Vec2, speed?: number); (couldn't think of a case where it's on |
Beta Was this translation helpful? Give feedback.
-
It would be fine some function that would simplify that an object moves to a certain position.
obj.moveTo(xPos, yPos, xVel, yVel);
Beta Was this translation helpful? Give feedback.
All reactions