Distance click of character

Started by Mehrdad, Wed 27/01/2016 15:25:10

Previous topic - Next topic

Mehrdad

Hi

I'm playing Black Mirror game and I notice it have great walking and pathfinding . I have two question:

1) In Black Mirror if you click very near to character for walking it doesn't move.It start to walking when you click at the special distance of character at least for one step walk.Is it possible in AGS?

2)Can we make more than 8 direction like 12 direction?
My official site: http://www.pershaland.com/

Cerno

I can help with 1). Place this in the beginning of your on_mouse_click function in GlobalScript.asc.
It computes the distance between mouse click and character via the pythagorean theorem and only moves the character if he is further away from the click than MIN_DISTANCE.

Code: ags

  if ((button == eMouseLeft) && (GetLocationType(mouse.x, mouse.y) == eLocationNothing))
  {
    float MIN_DISTANCE = 30.0;
    int mx = mouse.x;
    int my = mouse.y;
    int px = player.x;
    int py = player.y;
    int dx = mx - px;
    int dy = my - py;
    float dist = Maths.Sqrt(IntToFloat(dx*dx+dy*dy));
    if (dist > MIN_DISTANCE)
    {
      ProcessClick(mouse.x, mouse.y, eModeWalkto);
    }
    else
    {
      return; // ignore the click
    }
  }
  ProcessClick(mouse.x, mouse.y, Mouse.Mode);


Depending on what's already there, you may need some tweaking, as in remove any other ProcessClick(mouse.x, mouse.y, eModeWalkto) calls already there.
This depends on what user interface you chose. Instead of placing it in the beginning, you may need to integrate it in the code you are already using in on_mouse_click.
123  Currently working on: Sibun - Shadow of the Septemplicon

Snarky

Quote from: Cerno on Sat 30/01/2016 10:12:16
I can help with 1). Place this in the beginning of your on_mouse_click function in GlobalScript.asc.
It computes the distance between mouse click and character via the pythagorean theorem and only moves the character if he is further away from the click than MIN_DISTANCE.

This may or may not be a satisfactory solution, depending on how the walkable areas are laid out. Some issues:

First, it doesn't consider scaling, so what might be a small distance if the character is close/big could be a much larger distance if the character is distant/small. You can fix this pretty easily just by dividing the result by the current character scale.

Second, depending on exactly what you want the effect to be and how your walkable areas are set up, you may have to consider perspective foreshortening, which means that the on-screen vertical difference represents a longer distance for the character to walk than the horizontal difference. (In fact, if you click on the horizon, it should in principle represent an infinite distance.) AGS cheats: it just uses a fixed ratio between x-movement and y-movement, and you could probably do the same (multiplying the dx and dy by the horizontal and vertical walk speeds, respectively).

Finally, the method effectively assumes that the character will walk in a straight line. However, if there are obstructions, this may not be the case, and clicking on a spot a small distance away from the character's location may in fact be a command to walk a long way around. Since AGS doesn't give you access to the walk-path waypoints (you can add waypoints manually, but not AFAIK preview or inspect the ones AGS generates for a walk command), you can't really do anything about this. You can avoid making any walkable areas like that, or just accept that players first have to click on some other point to get far enough away from the destination to click on it again.

Cerno

Thanks for the corrections, as always things are not as easy ;)

About your last issue:
Would it be possible to define a region that covers all situations where you don't want the MIN_DISTANCE logic to apply?
When the player enters the region, a global variable is set (and unset when he exits the region).
Whenever the global variable is set, the MIN_DISTANCE logic would not be called
It's a bit crude since it also allows the player to walk short distances even if that click does not cause a long walk, but it should work, right?
123  Currently working on: Sibun - Shadow of the Septemplicon

Snarky

Yeah, you could do that. Or you could split the area into two walkable areas and say that if the current location and destination are in different areas, you should always move. But at this point we're probably over-engineering a solution to a cosmetic issue.

Another approach used in some (non-AGS) games is to say that the character can only stand in a certain limited number of positions: if you try to click to walk anywhere else, the game will pick the closest one and go there.

Also:

Quote from: Mehrdad on Wed 27/01/2016 15:25:10
2)Can we make more than 8 direction like 12 direction?

No, I don't think so. And because again AGS doesn't give you access to the waypoints of the walk-path (so you don't know exactly which direction the character is moving), there's no obvious workaround for it either, without coding up a total replacement for all the walk logic yourself.

SMF spam blocked by CleanTalk