# Aligning cards in a Playing Card Hand

I’m having trouble trying to align a series of cards in a player’s hand for a card game.

Basically, I’m trying to make it where all the cards in an array are aligned between two nodes, and as additional cards are added or if cards are removed, the cards will automatically realign to fit between the nodes.

I also want to possibly have whichever card is hovered over to scale (which I might handle with NGUI) while making sure the other cards stay aligned. I believe the best visual example would be like a Mac doc.

[11391-screenshot-2.png*_|11391]

I started with trying to get the cards to position between two point, but the cards aren’t positioning correctly

``````    void Update()
{
length = Vector3.Distance(node1.transform.position, node2.transform.position);

var no1 = node1.transform.position.x;
var no2 = node2.transform.position.x;

for (var i = 0; i < items.Count; i++)
{
var posX = (no1 + no2) / (i + 1);
items<em>.transform.position = new Vector3(posX, items_.transform.position.y, items*.transform.position.z);*_</em>
``````

}
* }*
Any help or examples would be great.
_*

Never, ever, ever, ever, ever, ever, ever, ever, ever try to write compact code.

Make your code as long as possible.

``````leftPoint = some Vector3
rightPoint = some Vector3
delta = rightPoint - leftPoint
howMany = items.Count (or whatever)
howManyGapsBetweenItems = howMany - 1
gapFromOneItemToTheNextOne = delta / howManyGapsBetweenItems
``````

then simply iterate

``````theHighestIndex = howMany - 1
for whichItemIndex = 0 through to theHighestIndex
{
items[whichItemIndex] =  leftPoint
items[whichItemIndex] += ( whichItemIndex * gapFromOneItemToTheNextOne )
}
``````

ok ?

Doing the “bounce” you describe is a totally, utterly separate question. (And quite difficult.) Please ask a new separate question for that.