when I click on a square on the board I can get the mouse position in screen coords but it isn’t the offset into the chessboard itself so I can’t yet convert that to a square clicked such as (x,y)=(3,4) where x = 1 to 8, y=1 to 8
Any ideas how I can get the mouse coords in relation to the chess board only?
I’ve been searching the forums for a few days now without working it out.
You could convert mouse *Screenspace *to Worldspace, trace and do InverseTransformLocation, this will spit out the mesh’s local coordinates (the offset you’re after), as seen below:
I assume I will need the get player controller to the left of ConvertMouseLocationToWorldSpace.
That’s what I currently have anyway from my messing about. I was trying the LineTraceForObjects and breakHitResult, but I see the line trace more going toward the camera rather than the board position being clicked.
I wasn’t aware of the GetActorTransform or InverseTransformLocation nodes, I will try to work out what they do, and give your technique a go today.
I’m now getting the board x,y values, although still not totally accurate. In some places I might get x=2, despite being about 4 or 5 pixels inside column 1.
I’m not sure I can count on each square (of the image material) being exactly the same width or height right across the board, even though by eye it appears uniform. I might have to do some pixel colour interrogation if we are close-ish to a border of 2 squares and make an intelligent guess or perhaps just deny the click if it is within say about 5% of the border.
So thank you again Everynone, I’m pretty happy to get this close.
[QUOTE=Loucsam;686801]
I’m not sure I can count on each square (of the image material) being exactly the same width or height right across the board, even though by eye it appears uniform. I might have to do some pixel colour interrogation if we are close-ish to a border of 2 squares and make an intelligent guess or perhaps just deny the click if it is within say about 5% of the border.
[/QUOTE]
The lack of accuracy might be caused by the fact that inverse transform gives you the coordinates of the mesh counting from the very centre - this includes the Z axis. So you’re not getting the XY of the surface. If you trace from an angle, there will be an offset. You may need to account for that in the calculations. Alternatively, you could place an invisible plane on top of the board and trace against that. Or do a normal trace and simply subtract the position of the board. Many ways to do what you need.
[HR][/HR]
On the other hand, consider the following alternative:
every chess field is a separate actor (or component)
Wow what a huge effort on your part to help. I thank you very much. Much appreciated.
Over a long time of finding small amounts of time I’ve tried various things, such as dynamically generating a board, but not doing all the things you are suggesting. I do like the look of my purchased chess model to the right in the image. The left ones are generated dynamically.
I will have a closer look at your techniques, I’m certain I can adopt some or all of it. I’m just reluctant to not use a purchased asset lol, but that’s a bad reason to not use dynamic methods I guess.
Many thanks once again.
p.s. you can see the line traces at x,y =(8,3) (H3) on my larger board, should give coords 8,3 but in the debug text you will see 7 and 3.