This repository was archived by the owner on Nov 12, 2024. It is now read-only.
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 |
0 replies
|
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 |
0 replies
|
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 |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
It would be fine some function that would simplify that an object moves to a certain position.
obj.moveTo(xPos, yPos, xVel, yVel);All reactions