Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Smooth movement takes a while to finish (https://forums.graalonline.com/forums/showthread.php?t=134266519)

Emera 05-26-2012 04:39 PM

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.

DustyPorViva 05-26-2012 05:04 PM

PHP Code:

player.-= cos(angle) * ((player.temp.dest[0])/distance) * walkingspeed;
player.+= sin(angle) * ((player.temp.dest[1])/distance) * walkingspeed

But the methods you're using seems overly complicated. Something like this should suffice:
PHP Code:

function onMouseWheel() {
  
temp.walkspeed .5;
  
temp.dest = {mousexmousey};

  
// Initiate distance to get loop started?
  
temp.dist 1;
  
  while (
dist .5) {
    
temp.deltas = {player.temp.dest[0],player.temp.dest[1]};
    
temp.dist = ((deltas[0] * deltas[0]) + (deltas[1] * deltas[1]))^.5;

    
player.+= (dx/dist) * walkspeed;
    
player.+= (dy/dist) * walkspeed;

    
player.chat "Moving... (Distance:" SPC dist ")";
    
sleep(0.05);
  }
  
  
player.chat "Finished movement";



Emera 05-26-2012 05:06 PM

Quote:

Originally Posted by DustyPorViva (Post 1695658)
PHP Code:

player.-= cos(angle) * ((player.temp.dest[0])/distance) * walkingspeed;
player.+= sin(angle) * ((player.temp.dest[1])/distance) * walkingspeed

But the methods you're using seems overly complicated.

They are compared to that! Thank you Dusty.

DustyPorViva 05-26-2012 05:11 PM

Quote:

Originally Posted by Emera (Post 1695659)
They are compared to that! Thank you Dusty.

I updated my post.


All times are GMT +2. The time now is 04:48 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.