Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tarrith opened this issue Jan 17, 2024 · 20 comments
Open

Comments

@Tarrith
Copy link

Tarrith commented Jan 17, 2024

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
Copy link
Owner

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

@Tarrith
Copy link
Author

Tarrith commented Jan 25, 2024

Were you able to replicate the strange behavior?

@Tarrith
Copy link
Author

Tarrith commented Apr 3, 2024

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

@KayelGee
Copy link
Owner

KayelGee commented Apr 3, 2024 via email

@Tarrith
Copy link
Author

Tarrith commented Apr 3, 2024

No problem, enjoy your holiday! :)

@KayelGee
Copy link
Owner

KayelGee commented Jun 9, 2024

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
Copy link
Author

Tarrith commented Aug 6, 2024

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
Copy link
Author

Tarrith commented Aug 6, 2024

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
Copy link
Owner

KayelGee commented Aug 6, 2024

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
Copy link
Owner

KayelGee commented Aug 7, 2024

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
Copy link
Author

Tarrith commented Aug 7, 2024

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.

@KayelGee
Copy link
Owner

KayelGee commented Aug 7, 2024

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.

offcenter_2.mp4
offcenter_3.mp4

@KayelGee
Copy link
Owner

KayelGee commented Aug 7, 2024

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
Copy link
Owner

KayelGee commented Aug 7, 2024

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
Copy link
Author

Tarrith commented Aug 7, 2024

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
Copy link
Author

Tarrith commented Aug 7, 2024

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
Copy link
Owner

KayelGee commented Aug 7, 2024

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
Copy link
Owner

KayelGee commented Aug 7, 2024

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

@Tarrith
Copy link
Author

Tarrith commented Aug 7, 2024

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.

@Tarrith
Copy link
Author

Tarrith commented Sep 9, 2024

So I haven't touched Foundry for a while, decided to have a little play last night, updated everything and...
...now it works.
Yay!
Thanks for all your work Kayel, I'm not sure why it wasn't working in the fist place, but I'm glad it is now :)

Even Grid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants