I need another another, how to make the robot walk to a point in the map....

Started by xboxown, Sat 04/02/2023 18:37:53

Previous topic - Next topic

xboxown

  I know what I am asking is trivial but to me it is not. I have a robot who joins the party later in the game. When I ask the robot to go to pick an item what I need it to do is walk to the item first, no matter what obstacles in its path before picking an item.  This is the code I did to make it happen...issue is with the y coordinate not the x coordinate.

Code: ags
    if ((cHelperCX100.y-itemY)>20)
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y-(cHelperCX100.y-itemY),eBlock,eWalkableAreas);
    }
    else if (cHelperCX100.y-itemY<20)
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y-(cHelperCX100.y+itemY),eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y,eBlock,eWalkableAreas);
    }

If you notice on this picture here https://imgur.com/RohPOgs if I tell the robot to pick up the globe it uses the x and y correctly to reach in front of the globe before it either talks out and says it cannot pick the item up or it picks the item up. As you can see no matter where I am at the bottom of the screen the robot does the job. Now, of course there are no obstacles in front of it or walls to go around it or anything like that so I have never tested it what happens if there are obstacles in it's path if it breaks the line of path or the robot is smart enough with the line of code above I have written to go around the obstacle until it reaches it's destination. But for now, it is working so far.

The issue I have is when I go up the screen and move to the top left side of the screen. That is when the robot does not behave correctly.

This is what I want it to do https://imgur.com/TC2PNUQ but it doesn't do it. This is why I put an X. This is what it does instead https://imgur.com/ecG2suO When it reaches at the end of the cliff up it acts like it cannot pick the item or pick the item up and as you can see the globe is all the way down there...it is not even close to the globe. Any advise in how to fix this issue?

eri0o

If both characters are solid they can block one another. You can make the robot non-solid and it should go through the character.

xboxown

I am not blocking the robot. Nothing to do with solid here. It is the robot not going down the stairs to reaching the globe. It simply moves all the way to the right. The robot passes through me as if I am invisible or don't exist as it walks to the destination specified.

xboxown

I did exactly what you said and see it did exactly what I don't want it to do. Like I told you, it is have nothing to do with solid or not as seen here https://imgur.com/Ot3iwUA

eri0o

On imgur, when you post, in the three dots at top right, there's a get share links, there the third option I believe gets you the image in bbcode tags (the forums tags), alternatively you can use the imgur url that begins with i letter and paste that as the link to the images here in the forums, it's a bit hard to click on the image link and remember from what it belongs to.

There's are two properties of the character that tells the destination, cEgo.DestinationX and cEgo.DestinationY, you can print those or just make a random object be set at that position on rep exec to see if the thing that is the destination is what you think it is.

Snarky

Quote from: xboxown on Sat 04/02/2023 18:37:53
Code: ags
    if ((cHelperCX100.y-itemY)>20)
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y-(cHelperCX100.y-itemY),eBlock,eWalkableAreas);
    }
    else if (cHelperCX100.y-itemY<20)
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y-(cHelperCX100.y+itemY),eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y,eBlock,eWalkableAreas);
    }

Let's examine your code a little more closely. The cHelperXC100.Walk() commands have inline calculations where you first add the cHelperCX100.x/y values, and then subtract them again. That will of course cancel out, so if we simplify, we get:

Code: ags
    if ((cHelperCX100.y-itemY)>20)
    {
      cHelperCX100.Walk(itemX,itemY,eBlock,eWalkableAreas);
    }
    else if (cHelperCX100.y-itemY<20)
    {
      cHelperCX100.Walk(itemX,-itemY,eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(itemX,cHelperCX100.y,eBlock,eWalkableAreas);
    }

It now should become apparent that the case if (cHelperCX100.y-itemY<20) is wrong. You're telling it to go to the -itemY coordinate, but this will be some point off screen.

I would also point out that the tests here are... odd. You're checking if some value is <20, then if the exact same value is >20, and finally, if neither is the case, you do the horizontal walk. In other words, you only do a horizontal walk if cHelperCX100 is exactly 20 pixels below itemY. I doubt that this is the effect you intend. I presume that what you're actually trying to do is to say that if the character Y value is within 20 pixels of the item Y value, we're close enough, so just move horizontally. Otherwise move in both the x and y direction. To do this, the tests need to be done like:

Code: ags
    if ((cHelperCX100.y-itemY)<20 && itemY-cHelperCX100.y<20)
    {
      cHelperCX100.Walk(itemX,cHelperCX100.y,eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(itemX,itemY,eBlock,eWalkableAreas);
    }

It would be even better to use an Abs() function, but let's skip that for now.

xboxown

Quote from: Snarky on Sat 04/02/2023 19:26:02
Quote from: xboxown on Sat 04/02/2023 18:37:53
Code: ags
    if ((cHelperCX100.y-itemY)>20)
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y-(cHelperCX100.y-itemY),eBlock,eWalkableAreas);
    }
    else if (cHelperCX100.y-itemY<20)
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y-(cHelperCX100.y+itemY),eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(cHelperCX100.x-(cHelperCX100.x-itemX),cHelperCX100.y,eBlock,eWalkableAreas);
    }

Let's examine your code a little more closely. The cHelperXC100.Walk() commands have inline calculations where you first add the cHelperCX100.x/y values, and then subtract them again. That will of course cancel out, so if we simplify, we get:

Code: ags
    if ((cHelperCX100.y-itemY)>20)
    {
      cHelperCX100.Walk(itemX,itemY,eBlock,eWalkableAreas);
    }
    else if (cHelperCX100.y-itemY<20)
    {
      cHelperCX100.Walk(itemX,-itemY,eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(itemX,cHelperCX100.y,eBlock,eWalkableAreas);
    }

It now should become apparent that the case if (cHelperCX100.y-itemY<20) is wrong. You're telling it to go to the -itemY coordinate, but this will be some point off screen.

I would also point out that the tests here are... odd. You're checking if some value is <20, then if the exact same value is >20, and finally, if neither is the case, you do the horizontal walk. In other words, you only do a horizontal walk if cHelperCX100 is exactly 20 pixels below itemY. I doubt that this is the effect you intend. I presume that what you're actually trying to do is to say that if the character Y value is within 20 pixels of the item Y value, we're close enough, so just move horizontally. Otherwise move in both the x and y direction. To do this, the tests need to be done like:

Code: ags
    if ((cHelperCX100.y-itemY)<20 && itemY-cHelperCX100.y<20)
    {
      cHelperCX100.Walk(itemX,cHelperCX100.y,eBlock,eWalkableAreas);
    }
    else
    {
      cHelperCX100.Walk(itemX,itemY,eBlock,eWalkableAreas);
    }

It would be even better to use an Abs() function, but let's skip that for now.

** grabs Snarky forehead and kisses his forehead ** IT WORKS! IT WORKS! IT WORKS! IT WORKS! THE ROBOT ACTUALLY WENT DOWN THE STAIRCASE AND WENT TO THE GLOBE!! IT WORKED! IT WORKED! IT WORKED! IT WORKED! IT WORKED!! I LOVE SMART PEOPLE! I LOVE SMART PEOPLE!

Khris

Glad it works but please do not quote the entire previous post. There's a Reply button at the bottom ;)

SMF spam blocked by CleanTalk