slow down object movement

Started by spook1, Wed 23/06/2004 20:55:15

Previous topic - Next topic

spook1

I do not succeed in making an object move slower than speed 1 in MoveObject function.
Trying to work around it with Wait in RepeatedlyExecute does not work either.

Is it possible anyway? A quick search through the fora only results in accopanying questions, but no answers.
Any ideas??

Regards, Martijn

P.S. first version of playable version in palent 1 is coming up soon :-)

SSH

This will only move one object slowly, and you need to set delay to be the delay between each move of your object. This is done as a room script here, but you could make it global...

#define SLOW_MOVE_TIMER 2

  int x0, y0, x1, y1;
  int dx, dy;
  int stepx, stepy;
  int delay=1;
  int fraction;
  int slowmoveon=-1;

function slowmove (int object, int x, int y) {
  slowmoveon = object;
  x0 = GetObjectX(object);
  y0 = GetObjectY(object);
  x1 = x; y1 = y;
  dx = x - x0;
  dy = y - y0;
  if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
  if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
  dy = dy << 1;
  dx = dx << 1;
  if (dx > dy) {
    fraction = dy - (dx >> 1);
  } else {
    fraction = dx - (dy >> 1);
  }
  SetTimer(SLOW_MOVE_TIMER, delay);
}
 
function slowmove_update () {
  if ((slowmoveon>=0) && (IsTimerExpired(SLOW_MOVE_TIMER))) {
    if (dx > dy) {
      if (x0 == x1) {
        slowmoveon=-1;
      } else {
        if (fraction >= 0) {
          y0 += stepy;
          fraction -= dx;
        }
        x0 += stepx;
        fraction += dy;
        SetObjectPosition(slowmoveon, x0, y0);
        SetTimer(SLOW_MOVE_TIMER, delay);
      }
    } else {
      if (y0 == y1) {
        slowmoveon=-1;
      } else {
        if (fraction >= 0) {
          x0 += stepy;
          fraction -= dy;
        }
        y0 += stepy;
        fraction += dx;
        SetObjectPosition(slowmoveon, x0, y0);
        SetTimer(SLOW_MOVE_TIMER, delay);
      }
    }
  }
}

function room_d() {
  // script for room: Repeatedly execute
  slowmove_update();
}
12

spook1

OK, this moves along a line.
is it also possible to slow down the movement along a walkable area? Do something with MoveObject(), and slow it down that way, by inserting Waits in clever points??

regards, Martijn

SSH

12

Radiant

How about SetGameSpeed () to some low value, and then speeding the regular characters up by increasing their walking speed? That might do the trick.

Barbarian

Not sure if I follow what you're trying to do, but if the object has a "view", then you can adjust each frame's speed setting, and you may also trying adding in extra duplicate frames to ever furthur slow down an animation sequence and you could even check the "Run the next loop after this to make a long animation" option if need be too? Oh well, just a thought.
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

Radiant

Yes, but that doesn't slow down the speed at which the object moves across the screen.

Barbarian

#7
How about perhaps setting up the object's movement with a timer?
Using the SetTimer and IsTimerExpired commands to check. So, let's say you use in a script:

SetTimer(1,1000);

Ã,  //this will set the timer 1 to expire after 1000 game cycles

then in the Repeatedly Execute part I think you might put:

If (IsTimerExpired(1)==1)
Ã,  Ã,  {code here}
//will execute the code if the timer 1 expires.

in your code, put the object to move "a step/ movement" the set distance you want it to move, then reset the timer and repeat. You could perhaps use a variable to check how many steps/movements your object makes and then have your object do something once it reaches it's destination?

Just another idea to consider. Hope it helps.

*Edit: Opps.. Sorry SSH.  ;)

Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

SSH

Quote from: Barbarian on Mon 28/06/2004 19:14:56
How about perhaps setting up the object's movement with a timer?
You mean like the code I posted in the second post in this thread?  ::)

Believe me, I've tried various things but the only other thing you can try is to make an animation for it, then make it a character instead of on object. If you have anti-glide mode on, then characters move slower than objects becuase they wait until their animation is finished before they move each time.

Either that, or write your own pathfinder algorithm...
12

SMF spam blocked by CleanTalk