outfrost / deckswipe

Single player card game skeleton based on Reigns and Lapse
MIT License
75 stars 29 forks source link

Animated cards fly away to high Z #11

Closed outfrost closed 6 years ago

outfrost commented 6 years ago

Best reproducible by repeatedly dragging a card in the middle of its converging animation.

Dragging a card keeps the Z constant, but the smooth animation doesn't - probably the cause.

outfrost commented 6 years ago

Found out that totalDisplacement in the snap animation code always has -10.0f as the z value.

image

outfrost commented 6 years ago

This line in OnMouseDrag() was the problem:

displacement.z = dragStartPosition.z;

Every time the player dragged a card, it would jump +10 units on Z and stay there until the transform position was reset to snapPosition, due the z value of 10.0f in dragStartPosition being accidentally doubled. Obviously, if a card was repeatedly dragged without reaching the snap position, the Z coordinate would continue increasing with each drag, eventually moving the card past the visible Z range.

Replacing the line with

displacement.z = 0.0f;

Fixed the issue.