In my Solitaire game I was changing the rotation of the cards in my Update() method to simulate the card being flipped over which worked fine.
I then converted the card flip to using animations instead so I could start learning about animations.
This also worked but in my code I also reset the card back to “face down” without the animation.
It looks like once you add an Animator component you can no longer change the transform of the gameObject.
I found that I could use the “Apply Root Motion” checkbox to allow my code to work but then my animations appear to be stopping part of the way though. I’m guessing this is because my code and the animation rotation changes are conflicting.
Just looking for some general advice on how you’re supposed to work with things like position and rotation in cod and in an animation at the same time.
Thanks!
ETA: code example
For my Animation its simply rotation.y = 0
on the 1st key-frame and rotation.y = 180
on the last key-frame.
The transition is based on a bool.
This is the line that doesn’t work unless Apply Root Animation
is turned on
CardModel.transform.localRotation = Quaternion.Euler(0, 180, 0);
Here’s my Card object layout
Card (GameObject)
- Collider Component
- Card. cs Script
- CardModel (GameObject, this is my Blender model)
- Animator
- Mesh Renderer
and card script attached to the parent
void Awake()
{
Collider = GetComponent<Collider>();
CardModel = transform.Find("cardModel").gameObject;
MeshRenderer = CardModel.GetComponent<MeshRenderer>();
Animator = CardModel.GetComponent<Animator>();
}
public void FlipUp()
{
isFaceUp = true;
Animator.SetBool("IsFaceUp", true);
}
public void FlipDown()
{
isFaceUp = false;
Animator.SetBool("IsFaceUp", false);
}
public void ResetCard()
{
isFaceUp = false;
transform.position = Vector3.zero;
transform.rotation = Quaternion.identity;
CardModel.transform.localRotation = Quaternion.Euler(0, 180, 0);
}