Walking & sliding along edges with keystrokes

Started by Ozwalled, Sun 01/02/2004 07:19:21

Previous topic - Next topic

Ozwalled

I've implemented the code that was described by Hollister Man at: http://www.agsforums.com/yabb/index.php?board=10;action=display;threadid=8303;start=msg132614#msg132614

But in some rooms, when I'm navigating around certain walkable area edges,  I find that I'm getting caught on them more than I'd like to. Can anyone thing of some way to add something to that code that would allow for the character's walking motion to slide along fairly smooth walkable area edges? (what I mean is that the player character would slide along the edge while continuing to walk in generally the same direction)

I was trying to think of a way to do this, but I'm stumped and have no idea whatsoever of where I'd even start. Can this even be done?

Kweepa

Try something like this:

Quote

int x = player.x;
int y = player.y;
int move = 1;

if (dir == UP || dir == DOWN)
{
  if (dir == UP)
  {
     y = y-1;
  }
  else
  {
     y = y + 1;
  }
  if (GetWalkableAreaAt(x, y) == 0)
  {
     if (GetWalkableAreaAt(x-1, y) > 0)
     {
         x = x - 1;
     }
     else
     if (GetWalkableAreaAt(x+1, y) > 0)
     {
         x = x + 1;
     }
     else
     {
         move = 0;
     }
  }
}
else
if (dir == LEFT || dir == RIGHT)
{
  if (dir == LEFT)
  {
     x = x - 1;
  }
  else
  {
     x = x + 1;
  }
  if (GetWalkableAreaAt(x, y) == 0)
  {
     if (GetWalkableAreaAt(x, y-1) > 0)
     {
         y = y - 1;
     }
     else
     if (GetWalkableAreaAt(x, y+1) > 0)
     {
         y = y + 1;
     }
     else
     {
         move = 0;
     }
  }
}
if (move > 0)
{
  // move to x, y
}

This will only slide against edges that are < 45 degrees to the direction of movement.
If you want to slide against more perpendicular edges, you'd need to probe a few pixels along each way.
And you might need to check the player can stand on the walkable area before moving there.
You'd have to call this several times if the character moves more than one pixel per update.

Hope that helps,
Steve

PS How do I format code on this board? It just trashes tab spaces.
Still waiting for Purity of the Surf II

SMF spam blocked by CleanTalk