# How could I show where a character may move on a grid within a certain distance?

Imagine a Chess scenario. A particular piece may move in any manner it likes but may only cover a certain number of spaces during a turn. Furthermore, once the square it goes to is chosen, it doesn’t immediately move. Rather, it waits until the enemy has chosen its move afterward, and then both move at the same time, to the coordinates that have been saved as variables for their destination.

Distance can be limited as one of the actions of pathfinding I think, but I have no idea how it might be shown. How can I draw a line from point a to point b (mouse pointer) unless point b is beyond a certain distance, in which case to point c, which is at the maximum distance from point a, and on the line between point a and point b? I tried looking at using a panel sprite, however, I can’t align a panel sprite between two objects, so far as I know, because there aren’t points on a panel sprite. Ideas?

You can draw a line with the shape painter.

To center a tiled sprite between to objects you can use

NewTiledSprite gets centerd between NewSprite1 and NewSprite2. You may need to use points on the sprites or CenterX() or Bounding Box positions.

Note: it’s center position

It might be worth looking into the linked objects behavior but there’s a little learning curve to it.

To use a shape painter, add a shape painter uncheck the draw shapes relative …
(The conditions are compare 2 numbers)

It’s quite lengthy, these are the end position for x and y. It calculates the X and Y positions based on the angle from the object to the cursor with a distance of 500 pixels.

``````X: NewSpriteA.XFromAngleAndDistance(NewSpriteA.AngleToPosition(CursorX(),CursorY()),500)
Y: NewSpriteA.YFromAngleAndDistance(NewSpriteA.AngleToPosition(CursorX(),CursorY()),500)
``````

call me a coward, but I think it might be better to center a panel square on a character.

Shape painter is too hard.

Can you post an image of the scene so we can get a better understanding and what you envision for the possible moves? Maybe add a drawing.

This uses the linked objects extension. I’ve been playing with it. It is based on another one of my projects.
I’m still learning and it is a bit complex IMO.

Try me: click either a green or purple piece, or drag it, the X is for targeting, you then click move, the slider sets the distance. It’s very crude and has bugs. It needs checks and balances to prevent certain actions.
https://gd.games/instant-builds/376dee20-8a63-45f4-b2f2-f6c355ba21d7

This is the source. Click the green [code] and [download zip] extract and open the JSON file.
Use as much or as little as you wish. Even if you don’t use it, it might inspire you.