- Home /
Turning animation while player presses button.
All right, let's go with some super simple/silly questions:
I have this GameObject. This gameObject has an animator attached to it. It performs several things like making the gameObject spawn, despawn, and all that stuff.
In the middle of all of this, I have a "Idle" animation that keeps the object centered and with its original scale. The reasons behind the need of this animation are [still unknown to me][1].
My problem here is that I need to make the GameObject rotate when (and while) a user presses a button, and then make the object maintain that animation when the user stops pushing the button. So, I need to either:
1) Get how can I set the initial transform of a animation to a specific value.
2) Learn how to make the initial transform of a given animation be the current transform of the GameObject.
Maybe there's something wrong with my "idle animation approach" (as it fixes the idle state to a specific transform), but I haven't managed to get why or how. [1]: http://answers.unity3d.com/questions/1282458/behavior-of-empty-state-machines-and-idle-empty-an.html
Answer by theANMATOR2b · Jun 23, 2017 at 03:43 PM
Have you tried to parent the animated game object to an empty game object - and control the "turn" of that empty game object without having to mess with the original game objects animation parameters?
As long as the original game object is not being translated (moved) in space - I think this is the setup I would use. Also I don't think I would control spawn/de-spawn in the animator - but if it works for you - keep it. :)
The parent animator idea is on the table, but the GameObject is a bit more complex that what I described. Creating another "layer" on the prefab would create additional headaches in the form of broken initializations and/or lost references. Also, the problem of keeping the turret turned would remain, right? Once you finish executing the animation, the animation state would return to "something" (which would be the "idle" animation), right?
"Also I don't think I would control spawn/de-spawn in the animator - but if it works for you - keep it. :) "
I meant "play the spawn/despawn" animations, hah. The actual spawn is controlled in code and is there where the trigger for the animations is fired.
I talked to a friend and gave me an idea, so I'm going to try creating a 360º turn animation for the idle state and setting its speed to zero, and the time to the angle turned. So if you press until the transform says it has turned 60º, when returning to "Idle State" the code tells the Animator to "play" Idle, with zero speed, starting at second 60.
Wish me luck!
Your answer
Follow this Question
Related Questions
Lipsync with phonem animations? 0 Answers
Shooting animation playing for longer than a second? 1 Answer
Animation Continue 0 Answers
Animation Running Game 0 Answers
Unity Animator cant play the same animation twice. 2 Answers