How to limit the movement of a piece

I’m currently making the pieces move when the left mouse button is released. But I want the piece to only be able to move within the highlights, but the highlights are a apart of the object, its just a different animation. I was thinking of comparing the value of center of the object to the position of the mouse. But I’m not sure how to go about it.

Do all the pieces move in the same way or is it like chess where each type has its own rules?

Each specific type has its own rule. For example, redbow and bluebow have the same movement. I need help with the bow and pegasus. The sword is fine because its a square and I have an event for when it isn’t in collision with the object it reverts to the original animation and it can’t move.

With Peg and Bow its just cause of the way the image is ig.

Screenshot 2024-07-10 142120

Screenshot 2024-07-10 142523

I figured it out!!! I realized I used the wrong action for the cursor!

For anyone that’s curious this is what worked:

Maybe if the different animations had their own collision mask. (you would have to use several masks for each animation since masks can’t be concave) You could then check if the cursor is touching the object and if the object is in collision with a piece, also if the cursor is touching the board object. Then it would be a matter of moving in a grid like way.

Edit. I wish certain characters on this forum didn’t disappear. Added preformatted.

trunc(CursorX()/gridSize)*gridSize+gridSize*.5 , trunc(CursorY()/gridSize)*gridSize+gridSize*.5

There might be easier way. I don’t have anything else right now.

Here’s my project. It has leftover variables. (click the green [code] and [download zip])
https://github.com/doug13579/gdevelop-check-for-valid-move

It uses a selected Boolean on the active object. That can be set on the first click. Maybe using modes.
I saved the X and Y with the thinking of comparing the x,y sets to make sure it’s not the center. IDK if X and Y are needed.

Yay! You sussed it! Make yourself a celebratory drink.

1 Like