Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: move from A to B  (Read 4367 times)

0 Members and 1 Guest are viewing this topic.

hubertMichael

  • Regular poster
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 155
    • View Profile
    • Shadow Of Nebula - our point'n click adventure game
move from A to B
« on: March 01, 2013, 11:34:41 PM »

Hi

I need simple function which will allow me to animate my object (pixel by pixel) from random coordinates to another random coordinates. Something similar to actor.GoTo(x, y)

Normally I would use GoTo but my object is not actor.

The biggest problem for me is that I don't know how to do it from a mathematical point of view. Any help would great.
Logged
Shadow Of Nebula fan page:

https://www.facebook.com/shadowofnebula

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: move from A to B
« Reply #1 on: March 02, 2013, 08:00:42 AM »

Hi.

I've use something like this:

Code: WME Script
  1. method FlyTo(var _x, var _y)
  2. {
  3.         var way;
  4.         var step;
  5.         var l = 8;
  6.        
  7.         way.x = _x - this.X;
  8.         way.y = _y - this.Y;
  9.        
  10.         var k = (Math.Abs(way.x)+0.00001)/(Math.Abs(way.y)+0.00001);
  11.        
  12.         if (k>1)
  13.         {
  14.                 step.x = sign(way.x)*l;
  15.                 step.y = sign(way.y)*l/k;
  16.         }
  17.         else
  18.         {
  19.                 step.y = sign(way.y)*l;
  20.                 step.x = sign(way.x)*l*k;
  21.         }
  22.        
  23.         this.StartX = this.X;
  24.         this.StartY = this.Y;
  25.        
  26.         this.EndX = _x; 
  27.         this.EndY = _y;
  28.        
  29.         this.StepX = step.x;
  30.         this.StepY = step.y;
  31.        
  32.         this.WayX = way.x;
  33.         this.WayY = way.y;
  34.  
  35.         if (k>=0.5)
  36.         {
  37.                 //playing animation of moving in horizontal axis
  38.                 if (way.x>0) this.PlayAnimAsync("right_walk.sprite");
  39.                 else this.PlayAnimAsync("left_walk.sprite");
  40.        
  41.         }
  42.         else
  43.         {
  44.                 //playing animation of moving in vertical axis
  45.                 if (way.y>0) this.PlayAnimAsync("down_walk.sprite");
  46.                 else this.PlayAnimAsync("up_walk.sprite");
  47.         }
  48.                
  49.         var dest = Math.Sqrt((_x - this.X)*(_x - this.X)+(_y - this.Y)*(_y - this.Y));
  50.                
  51.         while (dest>l)
  52.         {
  53.                 this.X = this.X + step.x;
  54.                 this.Y = this.Y + step.y;
  55.                 dest = Math.Sqrt((_x - this.X)*(_x - this.X)+(_y - this.Y)*(_y - this.Y));
  56.                 Sleep(30);
  57.         }
  58.  
  59.         this.X = _x;
  60.         this.Y = _y;
  61.         this.PlayAnimAsync("idle.sprite"); // Plays some idle animation after the moving
  62. }

There the sign function is:

Code: WME Script
  1. function sign (var _i)
  2. {
  3.          if (_i<0) return -1;
  4.          return 1;
  5. }

Hi

I need simple function which will allow me to animate my object (pixel by pixel) from random coordinates to another random coordinates. Something similar to actor.GoTo(x, y)

Normally I would use GoTo but my object is not actor.

The biggest problem for me is that I don't know how to do it from a mathematical point of view. Any help would great.
« Last Edit: March 02, 2013, 08:22:54 AM by 2.0 »
Logged

hubertMichael

  • Regular poster
  • ***
  • Karma: 3
  • Offline Offline
  • Posts: 155
    • View Profile
    • Shadow Of Nebula - our point'n click adventure game
Re: move from A to B
« Reply #2 on: March 03, 2013, 01:13:40 PM »

Thank you so much :)  That is exactly what I wanted
Logged
Shadow Of Nebula fan page:

https://www.facebook.com/shadowofnebula
 

Page created in 0.049 seconds with 25 queries.