Adam's Lair Forum

game development and casual madness
It is currently 2018/12/12, 12:41

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 2018/10/08, 19:56 
Newbie
Newbie

Joined: 2017/08/13, 16:30
Posts: 6
Role: Hobbyist
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:

Code:
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.


Top
 Profile  
 
PostPosted: 2018/10/09, 19:01 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 880
Location: Italy
Role: Hobbyist
Why not simply leverage the Parent / Child relationships? :]

Image

Gfycat Video - Click to Play. [Source]


Boom! no math required

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group