How to get player walking faster right than left

Started by tuckett, Wed 25/05/2011 01:24:46

Previous topic - Next topic

tuckett

Hi all,

I'm new here so be gentle  ;) . Basically I am trying to achieve the effect of an escalator. Have tinkered around with [SetWalkSpeed] but as soon as your walking you cannot set speed of character. Basically what I need is for my character to go slower left and faster right while on the escalator.

Any help appreciated, cheers.

Khris

This is going to get complicated, that's for sure :)

You could use a second character, a dummy that replaces the player character visually while on the escalator.
I'd use regions to determine the player's position, then use the dummy as soon as they step on the escalator.
The dummy mirrors the player's walking animation but isn't actually walking, it is moved instead by directly altering its x and y coordinate.
It's going to be more work if you want a sophisticated implementation.

Is the player supposed to continue walking after leaving the escalator? Is he supposed to stop walking and stand on the escalator after reaching the x coordinate of the click? Etc.

It would probably help to see the room background.

tuckett

#2
The player is supposed to jump to safety off the escalator onto an overhanging rail, and then walk on the rail. That part is working fine. Thanks for the quick reply.

The player is supposed to continue walking while on the elevator.

As for the dummy character bit, I have already tinkered with that, did you mean an actual character or an object animating like a character?  I'm not sure how to code a dummy mirroring a players walking animation - could you provide an example.


Khris

(Please don't quote the entire previous post.)

You could use an object, but using a character is easier to code and better to read.
Basically, to get an exact copy of the animation:

Code: ags
// inside room's repeatedly_execute

  if (cDummy.Room == player.Room)  {   // we move the dummy to the current room when we need him
    cDummy.Loop = player.Loop;
    cDummy.Frame = player.Frame;
  }


This will take care of the animation, the other thing is the actual movement.
The player is supposed to walk invisibly somewhere in the room, say on a narrow stretch of walkable area at the top of the room. It's not really important where, just that there's enough space so AGS can take care of the walking as usual.
As soon as the player character enters the escalator, he is moved to the left end of the dummy area and starts walking right. The dummy is sent into the room at the bottom of the escalator, mirroring the player's walking animation.
At the same time he's moved along the escalator by calculating his position using the escalator and walk speed together.
Like I said, it's complicated, but if done right could look very convincing.

To post images, upload them here: http://imgur.com (use the direct link)
For further help, reply to this post and click the link above the row of smilies.

tuckett

Okay so this is the room, player position at the left end on room load


Khris

#5
Ok, great, this should make things considerably easier.

Code: ags
// room script file

#define esc_speed 2

int walk_left, walk_right, walk_normal;

function room_Load() {
  walk_normal = player.WalkSpeedX;
  walk_left = player.WalkSpeedX - esc_speed;
  walk_right = player.WalkSpeedX + esc_speed;
}

function room_RepExec() {
  if (!player.Moving) player.x += esc_speed;
  if (player.x >= 430) {
    player.StopMoving();
    Display("You die.");
    player.x = 0;
  }
}

function on_mouse_click(MouseButton button) {

  // only catch walkto clicks
  if (button != eMouseLeft || mouse.Mode != eModeWalkto) return;
  
  int mx = mouse.x;
  if (mx < player.x) {
    if (player.WalkSpeedX != walk_left) {
      player.StopMoving();
      player.SetWalkSpeed(walk_left, player.WalkSpeedY);
    }
    player.Walk(mx, player.y, eNoBlock, eAnywhere);
  }
  else if (mx > player.x) {
    if (player.WalkSpeedX != walk_right) {
      player.StopMoving();
      player.SetWalkSpeed(walk_right, player.WalkSpeedY);
    }
    player.Walk(mx, player.y, eNoBlock, eAnywhere);
  }
  ClaimEvent();
}


I tested this with a 320 pixel version but it should work fine regardless. Tinker with the speed setting at the top.
Note that this works without any walkable area. The player can't move up and down, this can easily be added though.

As you can see I've added a on_mouse_click function to the room script. What AGS does is call that one, then the global one. Except if I use ClaimEvent(), which I do after processing only a Walkto click. So the function simply replaces standard Walkto click handling with custom code.


SMF spam blocked by CleanTalk