View Single Post
  #1  
Old 05-26-2012, 04:39 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Smooth movement takes a while to finish

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 = {mousexmousey};
  
temp.angle getangle((player.temp.dest[0]), (player.temp.dest[1]));
  
temp.odist vectordist({player.xplayer.yplayer.z}, {dest[0], dest[1], player.z});
  
  while(
player.!= temp.dest[0] && player.1!= temp.dest[1]) {
    
temp.distance vectordist({player.xplayer.yplayer.z}, {dest[0], dest[1], player.z});
    
player.-= cos(angle) * (distance odist);
    
player.+= 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.dest[0];
  
player.dest[1];

But that resulted it a jolty finish, which isn't what I want.
Reply With Quote