Stuck on math/logic problem, help appreciated - trying to make chess

Hi ive been stuck on this for while
im trying to make chess

the table PieceMovement is a range of movements the piece can do
for example pawn is (0,2), it’ll be able to move 2 spots ahead

CurrentPosition is a Vector2 where the current piece is on the board

the repeat adds a position per loop until it reaches the range
for example pawn is (0,2), itll return with this
image

this works until diagonals hit a wall


it should be stopping instead of dragging along the wall
ive been stuck on this for a while and idk how to Fix it

it might have something to do with the math.clamp as its capping it at 8 which makes the x value 8; it should stop there instead of going to 8

I can’t script well, so sorry if you’re already doing this, but are you checking if the “target square” is a real location to travel to?
You clamp your values at eight, so if a piece tried to move to, say, (7, 10), the value gets clamped and turned into (7,8), which is a real location, so it gets shown.

I believe to fix this, add a check whether the target square is possible to travel to, and if not, stop displaying squares across that line. I don’t believe this would need the clamp function

2 Likes

thank you , i removed the clamp its working now :smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.