Change visual angle of partial objects (but keep all calculations happening one way)

So I am making a chess-esque game. The game was initially planned to be built left to right but recent review with friends revealed that they want an ability to rotate at will.

So initially I thought I could just look at the relationship of positions on the board and simply math out what the rotation would look like. It simply looks like it would be the difference from the center and then inverting X and Y positions.

For instance, on an 8 by 8 a unit that is on 4,4 would rotate to 5,4 then 5,5 and finally 5,4.

Similarly, a unit on 3,4 is going to rotate to 4,6 then 6,5 and finally 5,3.

In an 8 by 8 board the top-left of the dead center is 5,5. So we can say:

CenterX or Cx = 5
CenterY or Cy = 5

Distance of unit’s origin (top-left X) from CenterX or Dx = x - Cx
Distance of unit’s origin (top-left Y) from CenterY or Dy = y - Cx

RotatedX or NewX or Nx= Cx + Dy
RotatedY or NewY or Ny = Cy - Dx - 1

So let’s look at the first example:
(4,4) → (4,5) → (5,5) → (5,4)

When X = 4 and Y = 4, Dx = 4 - 5 = -1 and Dy = 4 - 5 = -1
Nx = Cx + Dy = 5 - 1 = 4
Ny = Cy - Dx - 1 = 5 + 1 - 1 = 5
(4,5)

When X = 4 and Y = 5, Dx = 4 - 5 = -1 and Dy = 5 - 5 = 0
Nx = Cx + Dy = 5 - 0 = 5
Ny = Cy - Dx - 1 = 5 + 1 - 1 = 5
(5,5)

When X = 5 and Y = 5, Dx = 5 - 5 = 0 and Dy = 5 - 5 = 0
Nx = Cx + Dy = 5 - 0 = 5
Ny = Cy - Dx - 1 = 5 + 0 - 1 = 4
(5,4)

When X = 5 and Y = 4, Dx = 5 - 5 = 0 and Dy = 4 - 5 = -1
Nx = Cx + Dy = 5 - 1 = 4
Ny = Cy - Dx - 1 = 5 + 0 - 1 = 4
(4,4)

Similarly, second example would fit the rule as well:
(3,4) → (4,6) → (6,5) → (5,3)

When X = 3 and Y = 4, Dx = 3 - 5 = -2 and Dy = 4 - 5 = -1
Nx = Cx + Dy = 5 - 1 = 4
Ny = Cy - Dx - 1 = 5 + 2 - 1 = 6
(4,6)

When X = 4 and Y = 6, Dx = 4 - 5 = -1 and Dy = 6 - 5 = 1
Nx = Cx + Dy = 5 + 1 = 6
Ny = Cy - Dx - 1 = 5 + 1 - 1 = 5
(6,5)

When X = 6 and Y = 5, Dx = 6 - 5 = 1 and Dy = 5 - 5 = 0
Nx = Cx + Dy = 5 + 0 = 5
Ny = Cy - Dx - 1 = 5 - 1 - 1 = 3
(5,3)

When X = 5 and Y = 3, Dx = 5 - 5 = 0 and Dy = 3 - 5 = -2
Nx = Cx + Dy = 5 - 2 = 3
Ny = Cy - Dx - 1 = 5 + 0 - 1 = 4
(3,4)

OK now that I have proven that this can work - I am wondering if there is a more elegant way of doing this. The reason why I say this is because:

  • The game will have online play and two people can be in different orientation
  • Currently only pawn is angle dependent (all other units would have same movement irrespective of angle). Pawn can only move right or left or up or down depending on orientation. So I would need to start doing movements based on angle :frowning:

Really i do not get what you mean

Are we talking about rotating what you see?
Cause that would be rotating a layer

Rotating the layer camera would be the easiest option. Then you don’t need to worry about the calculations of all the pieces, or worry about movements based on angles.

Movement determinations would be one plane for the whole board, and can be made to look different based on how the view has been rotated.

OMG - I didn’t know rotating layer existed. I will explore that but I think it will have some complications. Let me show the picture of polished version.

So the way the aesthetics of the game are set up - I wouldn’t want the clouds or buttons (flag and pinwheel etc) to move.

Secondly, when the deployed characters and tiles rotate, I would still like them to face upwards.

Does that mean…

(1) Put the tile and characters in their own layers (so I could rotate them and leave the rest in a different layer)?

(2) Once Rotating both characters and tile - rotate the character 90°?


Last wrinkle in all this is animations - to play the animations correctly - I would be first placing the characters to the left or right of the dying unit. Rotating the layer probably would need adjusting of that aspect (as well correct?)

OMG! You are amazing. You and Zero4 responded similarly.

I will try to learn layer camera this weekend. I had some additional questions. Can you scroll up to see the follow-up questions to Zero4?

I am thinking the animation piece might be best addressed by perhaps hiding the units in play and then running an animation (spawned dummy units) at where the dying unit needs to be. It would look a bit cheap but would save me tons of conditional coding.

Thoughts?

I am still not 100% sure if we are talking about same thing

Press LMB or RMB


You need to change center point to bottom of your object
Since that works like pivot
Think of it as center of clock arm
It is never in center of it
But like on bottom of it yet clock arm spin around it

If this is what you want
Then clouds (which would NOT rotate)
Is just matter of putting them on DIFFERENT layer than the one you rotate
I rotate base layer default value for it is “”

And you still can animate your clouds like you would normally animate them in any 2d game

I am 89% confident that we are talking about the same thing, my friend.

I will check out your game over the weekend and report back.

I still think the animation portion may need some finessing but that is a demon for a few weeks out.

1 Like

Yes.

Yes, you’ll need to rotate the characters the same angle that you rotate the camera (as ZeroX4 wrote too).

Yeah, that bit will need a bit of work and take the rotation/angle into account. Because a dying unit on the left of the character on the actual board will be displayed as being below the character on a view rotated 90 degrees.

This is exactly it. Thank you so much, ZeroX4 :smile:

1 Like

Thank you so much. Yup - It is making sense to me.

For the animation, I think it would be easier to create dummy units that play the animation and then hide them afterwards.