KayelGee / token-attacher

MIT License
11 stars 18 forks source link

Tokens become offset when rotating a larger token on a Hex Column Grid. #108

Open Tarrith opened 7 months ago

Tarrith commented 7 months ago

When a Controlling Token is attached to a larger Token with its 'Width' increased, the hexagon becomes offset when rotating if the grid is set to Hexagonal Columns.

Hex Columns: Rotation becomes offset.

Hex Column

Hex Rows: Rotation is fine.

Hex Row

KayelGee commented 7 months ago

That's honestly so strange, that column vs row behaves differntly. I might actually take a look at that.

Tarrith commented 7 months ago

Were you able to replicate the strange behavior?

Tarrith commented 4 months ago

Hey KayelGee, do you need me to send any files or anything to make it easier for you to debug?

KayelGee commented 4 months ago

Hey sorry I'm on vacation so i can't really check for the next 3 weeks. I'll take a look once I'm back

Tarrith @.***> schrieb am Mi., 3. Apr. 2024, 15:44:

Hey KayelGee, do you need me to send any files or anything to make it easier for you to debug?

— Reply to this email directly, view it on GitHub https://github.com/KayelGee/token-attacher/issues/108#issuecomment-2033679479, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE5ONVID425HEK6SPE7J2WDY3OXNJAVCNFSM6AAAAABB6NJ4P6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZTGY3TSNBXHE . You are receiving this because you commented.Message ID: @.***>

Tarrith commented 4 months ago

No problem, enjoy your holiday! :)

KayelGee commented 2 months ago

Sorry I can't wrap my head around that. I'm pretty sure it has to be how hex tiles determine the center of the token from their xy position, but I'm too stupid to figure out how to do it for now.

Tarrith commented 2 weeks ago

Yeah, it's definitely a Hex grid issue, maybe with Foundry itself. I changed the grid to Sqaure using the same tokens and sizes with no issue with skewering. I then changed the orientation of the Hex Grid to Hexagonal Columns - Even and it worked fine also. When I set it back to Odd...it started skewing again.

So to clarify, the skewering only happens when the Heaxagonal Columns are set to Odd.

image

Square Grid Square Grid

Hex Grid - Even Even Grid

Tarrith commented 2 weeks ago

Ah well, I guess I'll either have to the map with the Hex orientated the other way or start using a square grid XD

Thanks for trying anyway :)

KayelGee commented 2 weeks ago

Just to add a little more info.

This isn't a foundry bug. It has to do with how I offset the elements. To do that I calculate the center of for example a Tile and basically create an offset vector from the center of the token to the center of the Tile. This is later used to place the Tile at the correct position and rotation.

In Square grids the center is easy to calculate, because the x,y coordinate is the top left corner and you just need to add half the width and height to that. That works for both Tokens and Tiles.

In Hex grids it's a little more complicated to calculate the center, because it depends on the type of hex you're using. The formula isn't actually that complicated it should be basically x,y + half the spacing(see https://www.redblobgames.com/grids/hexagons/#spacing). The token center has to be calculated as a Hex and the Tile center as a square. The rest of the process should be the same.

I don't know what I did wrong but I couldn't get the code to behave as I described above. I'd need to add more visualization to see what the problem is. But now that I have written this I might've missed the fact, that Tokens need to have their center calculated as a Hex and Tiles as a Sqaure.

KayelGee commented 2 weeks ago

I found my issue and it's something that's really odd. When you go to your Token Configuration then there's an option called Hexagonal Shape. When you change that you'll see that foundry moves the image of the Token depending on this setting. But it's not only visual, the axis of rotation moves aswell. My problem came from the fact that the default setting "Ellipse (Variant 1)" is actually not in the mathematical center when your Token is size 2. When you switch to any of the Rectangle variants the rotational axis is actually in the mathematical center.

So the math I used was correct but foundrys default setting is an oddity. I don't understand why they aren't using the actual center for all variants. Maybe this is a bug. I'll have to have another look at this on another day.

Tarrith commented 2 weeks ago

All good, thanks for looking into this. It's only because a lot of wargame hex maps use the grid with the hexes flat on top and I have to admit...it looks so jarring with the hexes rotated :)

"but I'm too stupid to figure out how to do it for now."

KayelGee commented 2 weeks ago

To highlight this I've added two videos showing the issue. The red rectangle shows the mathematical centered bounding box with a centered cross. The white box shows the different variants. One video shows a size of 2 and the other a size of 3.

https://github.com/user-attachments/assets/a3d75f6f-4aed-4d1c-ba3d-bf50ab2e9f64

https://github.com/user-attachments/assets/aabc70d2-d5ec-4856-83d1-83bea4eb9e3d

KayelGee commented 2 weeks ago

All good, thanks for looking into this. It's only because a lot of wargame hex maps use the grid with the hexes flat on top and I have to admit...it looks so jarring with the hexes rotated :)

"but I'm too stupid to figure out how to do it for now."

* Heck no! You created this awesome mod in the first place that only has a bug for a niche issue. Please don't say that!
  Token Attached is wicked cool! Heck I couldn't even start to fathom the maths needed let alone code any of it!
  Don't let my issue get you down.

What does it have to do with flat top hexes? The issue exists in both. Also don't worry the issue didn't get me down. At the time I just wanted to say that I don't understand what the actual issue was and what was wrong with my approach to solve it, so I had to put it to rest.

KayelGee commented 2 weeks ago

I've asked in the foundry discord if this is intentional or not. If it's intentional I'll revisit this. For now I'll put out an update which should alleviate the issue if you choose a rectangle variant.

The update will be out in the next minutes.

You'll have change the control token to a Rectangle variant and redo your attachments. When you have time, can you confirm if this solves the issue?

Tarrith commented 2 weeks ago

I'm sorry if I haven't made this clear. Rotation works fine when the Grid Type is set to "Hexagonal Columns - Even" or "Hexagonal Rows Even" image

It's only when the Grid is set to Hexagonal Columns - Odd" or "Hexagonal Rows - Odd" that the skewering occurs. image

Mathematically I'm sure it should work in both orientations, hence my wondering if it was a bug in Foundry itself.

Tarrith commented 2 weeks ago

Sorry if this is frustrating for you, I can understand that. Ill give the new version a go in about an hour when I get back home :)

KayelGee commented 2 weeks ago

I'm sorry if I haven't made this clear. Rotation works fine when the Grid Type is set to "Hexagonal Columns - Even" or "Hexagonal Rows Even" image

It's only when the Grid is set to Hexagonal Columns - Odd" or "Hexagonal Rows - Odd" that the skewering occurs. image

Mathematically I'm sure it should work in both orientations, hence my wondering if it was a bug in Foundry itself.

No that's what I'm saying the issue exists in all four hex grid types. Unless you changed the hexagonal shape of your control token you should see the issue in every hex grid type.

KayelGee commented 2 weeks ago

Also I confirmed it, it's not a bug it's an intended change in v12.

Tarrith commented 2 weeks ago

K. Well It was working with the Hex Evens but not the Odds so...I don't know I'm kinda lost. And I tried the update, but now it's not attaching at all. Too late at night for me to try anything else. Tonight.