Problem animating the position of a GameObject in Unity while moving it

时间:2019-03-17 22:53:21

标签: unity3d animation mecanim

I am working on moving a Cube across the screen when I press an arrow and display two different animations depending on if it is moving or idle. I used a very basic translation to do this when I press the right arrow. I have two different animation states that work fine independently. One spins the cube when it is “idle” and the other makes to bounce up down in the “right” state. Both are 1 second animations. The idle animation spins the cube 360 degrees, and the right animation will move the cube up 1 unit then back down to its original position. Everything works well by itself. I included an image for the states for the animation.

Cube Animation States

In order to get the movement working with the animations I made an empty GameObject and made the cube a child if it. When the cube is idle it spins, and when I press right it moves and bounces up and down. The problem is when I release the right arrow the cube snaps back to its original position from the start of the last bounce animation. If I hold right for 10 seconds, and release it will only snap back to the beginning of the most recent iteration of the bouncing animation (not to when I started pressing right). Does anyone know why this would happen? I tried changing some of the settings for the transitions, but it doesn’t seem like that is the problem.

2 个答案:

答案 0 :(得分:0)

您是否可以在任何情况下检查闲置动画是否修改其位置。

答案 1 :(得分:0)

首先,您不能使用动画来移动游戏对象。

您可以在立方体中有旋转动画,但在平移部分中没有。

因为当动画在状态之间切换时,对象将移动到其原始位置。

解决方案: -创建脚本并将脚本附加到该游戏对象。 -使用翻译功能移动对象