|Adam's Lair Forum
|Help with calculating positions on angled object
|Page 1 of 1|
|Author:||tufduck01 [ 2018/10/08, 19:56 ]|
|Post subject:||Help with calculating positions on angled object|
I have an issue a little more related to maths than Duality. Let's see if I can explain good enough for anyone to help me here...
I'm developing a card game. The cards are rectangular game objects. The cards can be "exhausted" (a card game term, meaning rotated 90 degress clockwise). On the cards you can place tokens. The tokens have fixed positions on the cards. For instance, damage tokens are placed bottom left, resource tokens bottom center and progress tokens bottom right.
Right... Now I need to calculate those specific positions for the tokens, like this:
Vector3 destinationPos = cardObject.Transform.Pos;
if (tokenName == "Damage")
gameObject = DamageTokenPrefab.Res.Instantiate(fromPos, 0, cardObject.Transform.Scale);
destinationPos += new Vector3(-(0.3f * cardWidth), (0.3f * cardHeight), 0);
else if (tokenName == "Resource")
gameObject = ResourceTokenPrefab.Res.Instantiate(fromPos, 0, cardObject.Transform.Scale);
destinationPos += new Vector3(0, (0.3f * cardHeight), 0);
else if (tokenName == "Progress")
gameObject = ProgressTokenPrefab.Res.Instantiate(fromPos, 0, cardObject.Transform.Scale);
destinationPos += new Vector3((0.3f * cardWidth), (0.3f * cardHeight), 0);
This works, as long as the card has an angle of zero. If the card is exhausted (or at some other angle), the token positions are far off.
How do I calculate the tokens position regardless of the card angle? Is there some clever maths, like some matrix operations or whatever, that I can take advantage of?
Maybe not so good explanation, but I hope I've made myself clear.
|Author:||SirePi [ 2018/10/09, 19:01 ]|
|Post subject:||Re: Help with calculating positions on angled object|
Why not simply leverage the Parent / Child relationships?
Gfycat Video - Click to Play. [Source]
Boom! no math required
|Page 1 of 1||All times are UTC + 1 hour [ DST ]|
|Powered by phpBB® Forum Software © phpBB Group