Hi, I’m working on a card game, and I need to create some sort of “object rotator” to show some cards. Maybe a picture will explain better what I’m trying to achieve:
[3137-rotator.jpg*|3137]
- The numbered red boxes represent the cards (they are always facing the camera).
- The big black circle is the Transform the cards are rotating around to
- The yellow line is the circle on which the cards are constrained
- The blue line is the radius of this circle
I tried implementing this stuff with the following code (which I found on the forum):
void DistributeOnCircle ()
{
for (int i = 0; i < cards.Length; ++i)
{
float theta = (2 * Mathf.PI / cards.Length) * i;
float x = Mathf.Cos(theta);
float z = Mathf.Sin(theta);
cards*.position = new Vector3(x, transform.position.y, z);*
- }*
}
It kinda works, but clearly I did not understand how it exactly works, so I have a few questions:
1) how can I set the radius in that code?
2) how can I make one of the cards always appear in front of the camera (exactly like in the picture: card 1 is right in front of the camera; if I press a key and rotate the cards, card 2 (or card 5, in that case) should face the camera, too). I tried to rotate the Transform with iTween, setting the amount of the rotation to 360 / numberOfCards, but it’s not working as expected…
Here’s another picture explaining what I need:
[3148-rotator2.jpg|3148]*
On the left, the current behaviour. On the right, what I need to do: one of the cards should always be aligned with the camera on the X axis, and all the others are spaced evenly on the circle.