I don't really know where to go with this one O.O I'm attempting to smoothly move the player from one point to another. I've got the smooth movement working, but as the player is slowing down (closing in to the final destination), the movement slows and it takes a good 5 seconds to finish the movement even though nothing nothing visibly happening.
Here's the code:
PHP Code:
function onMouseWheel() {
temp.dest = {mousex, mousey};
temp.angle = getangle((player.x - temp.dest[0]), (player.y - temp.dest[1]));
temp.odist = vectordist({player.x, player.y, player.z}, {dest[0], dest[1], player.z});
while(player.x != temp.dest[0] && player.y - 1!= temp.dest[1]) {
temp.distance = vectordist({player.x, player.y, player.z}, {dest[0], dest[1], player.z});
player.x -= cos(angle) * (distance / odist);
player.y += sin(angle) * (distance / odist);
player.chat = "Moving... (Distance:" SPC distance @ ")";
sleep(0.05);
}
player.chat = "Finished movement";
}
I tried to solve it by doing something like:
PHP Code:
if (distance <= 0.1) {
player.x = dest[0];
player.y = dest[1];
}
But that resulted it a jolty finish, which isn't what I want.