Quantcast
Channel: Questions in topic: "hold"
Viewing all articles
Browse latest Browse all 154

Controlling body parts during animations with scripts

$
0
0
I'm making an archer in a 2D game. I've made an arrow drawing animation which leaves the player aiming in a horizontal direction. I now want the player to move the aiming direction by moving the mouse around. I know how to calculate the aiming angle (from the center of the player). So the thing I'd like to know is how do I rotate my body parts around to match the direction I am aiming in? This is what I've tried: I've made a new animation, "hold", which is automatically transitioned to after the arrow draw animation. It is just one frame, and it is a copy of the last frame of the drawing animation. As long as the player holds the mouse, we are in the hold animation. Now I wanted to rotate the right bracer and left arm via scripting, but alas this did not work: if (anim.GetCurrentAnimatorStateInfo (0).IsName ("hold")) { rightBracer.rotation = Quaternion.Euler(0,0, aimAngle + 474.3156f); // 474. is the rotation when the player is aiming right leftArm.rotation = Quaternion.Euler(0,0, aimAngle + 69.52766f); } I've figured out that the reason is probably that the animation clip "hold" is overwriting these changes. So there's two possible solutions I can think of but I do not know where to start for both of them: 1) There could be a way to directly overwrite the animation or atleast make sure the animation does not overwrite my scripting values. 2) I should delete the hold animation, so my player is no longer in an animation state. But how does this work? Should I make a transition to the "Exit" state in my animator controller? How do I stay in (a modified version of) the last frame of the drawing animation? And how do I go back to animations? How would you fix this?

Viewing all articles
Browse latest Browse all 154

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>