Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 05-26-2012, 05:04 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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";

Reply With Quote
  #3  
Old 05-26-2012, 05:06 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
Quote:
Originally Posted by DustyPorViva View Post
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.
Reply With Quote
  #4  
Old 05-26-2012, 05:11 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Emera View Post
They are compared to that! Thank you Dusty.
I updated my post.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 11:18 AM.


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