unity3d 动画制作

Animation is one among the two components of a game, which brings it to life (the other being audio). Unity’s animation system is called Mechanim, and its power lies in bring humanoid models to life. In previous versions, another component called “Animation” was used, but it has now been depreciated in the recent versions of Unity.

动画是游戏的两个组成部分之一,使游戏栩栩如生(另一个是音频 )。 Unity的动画系统称为Mechanim,其功能在于使人形模型栩栩如生。 在以前的版本中,使用了另一个称为“动画”的组件,但现在在Unity的最新版本中已弃用了该组件。

Here in this tutorial we will see the basics of how the Animator is used for creating animations. We will make a mini game module of a door that opens on us pressing space and then closes if we press space again. So lets start our journey and hope in the end, we all get through that door.

在本教程的此处,我们将了解如何使用Animator创建动画的基础知识。 我们将制作一个迷你游戏模块,该模块的门会在我们按下空间时打开,然后在我们再次按下空间时关闭。 因此,让我们开始自己的旅程,并希望最终,我们所有人都能渡过那扇门。

1.创造环境 (1. Creating our Environment)

In this module we will set up our environment. This means that we will be creating:

在本模块中,我们将设置我们的环境。 这意味着我们将创建:

  • The base/ground

    基地/地面

  • A 4 walled structure

    四壁结构

  • Our door

    我们的门

  1. To create the base right click on the Hierarchy panel>3D Objects>Cube. Double click on the Cube object in the Hierarchy. The Scene Window focuses on the cube.

    要创建基础右键,请单击“层次结构”面板>“ 3D对象”>“多维数据集” 。 双击层次结构中的多维数据集对象。 场景窗口专注于多维数据集。

  2. Now in the Inspector panel, you will see the transform component. Make sure the position and rotation of the cube is (0,0,0) and the scale is (1,1,1). Change the scale values to (5, 0.5, 5). This will be our floor. Rename the object “Floor” (without quotes) by selecting the cube in Hierarchy, pressing F2 key, typing the name and pressing enter.

    现在,在“检查器”面板中,您将看到转换组件。 确保立方体的位置旋转为(0,0,0), 刻度为(1,1,1)。 将比例值更改为(5,0.5,5)。 这将是我们的地板。 通过在“层次结构”中选择多维数据集,按F2键,键入名称并按Enter,将对象重命名为“ Floor”(不带引号)。

  3. Similarly create 3 more cubes and arrange them in such a way that they make 3 walls for the floor. This is a task for the reader.

    同样,再创建3个多维数据集,并以使其在地板上形成3面墙的方式排列它们。 这是读者的任务。

  4. Now for the door. Basic doors can be of 2 types, sliding or hinged. We will go for the sliding door. Now similar to the last step create another wall to make a room without a roof. Name the fourth wall as “Door”. This will be our door.

    现在换门了。 基本门可以分为滑动门或铰链门两种。 我们将去推拉门。 现在类似于最后一步,创建另一面墙以形成没有屋顶的房间。 将第四面墙命名为“ Door”。 这将是我们的门。

2.建立我们的观点 (2. Setting Up Our View)

This module is for those who do not have an Animator panel open. If you do, skip to the next section.

该模块适用于那些没有打开“ Animator”面板的用户。 如果您这样做,请跳至下一部分。

To open the Animator panel, click on the Window option on the menu bar and from the drop down list select Animator.

要打开“动画器”面板,请单击菜单栏上的“窗口” 选项,然后从下拉列表中选择“动画器”。

Also from the same Window menu, select the Animation option to open the Animation panel.

同样从同一“窗口”菜单中,选择“ 动画”选项以打开“动画”面板。

We will use both of these to create our sliding door animation.

我们将使用这两者来创建滑动门动画。

3.为门创建动画 (3. Creating Animations for the Door)

For creating animations, we first create the animation movements, then we order those movements in the form of a state machine (look it up!) so that we are able to transition from one state to another. Do not be intimidated by the animator figure below. After this tutorial, you would be making these in your sleep.

为了创建动画,我们首先创建动画运动,然后以状态机的形式对这些运动进行排序(查找!),以便我们能够从一种状态转换为另一种状态。 不要被下面的动画师图吓倒。 学习完本教程后,您将在睡眠中制作这些。

Now for creating the animations

现在用于创建动画

  • Select the Animation panel and click on Create.

    选择“ 动画”面板 ,然后单击“创建”。

  • Name you animation “DoorOpen” and save it in the Asset folder. Similarly make another animation called “DoorClosed” and save it.

    将动画命名为“ DoorOpen”,并将其保存在Asset文件夹中。 同样,制作另一个名为“ DoorClosed”的动画并将其保存。

  • Select the created animation files one by one and uncheck the “Loop Time” option.

    逐一选择创建的动画文件,然后取消选中“循环时间”选项。

  • Now pay attention to this point as it is the step that creates magic. Select the “DoorOpen” animation in the Animation panel. You wills see a time line. This is called the Dopesheet (maybe cuz its ‘dope’.... I don’t know). It will act as the timeline of the things that will happen during the animation.

    现在注意这一点,因为这是创造魔术的步骤。 在“动画”面板中选择“ DoorOpen”动画。 您会看到一条时间表。 这就是所谓的Dopesheet(也许是因为它的'dope'...。我不知道)。 它将作为动画过程中发生的事情的时间表。

  • Click on the Add Property button and select Transform >Position. Here we can see that 2 diamonds have formed on the time line. These depict keypoints at which we know the properties of the object. Given a set of keypoints, Unity automatically interpolates and generates the movement that is to occur between these two keypoints. Keep this feature in mind as you move ahead.

    单击添加属性按​​钮,然后选择转换>位置。 在这里,我们可以看到在时间线上形成了2颗钻石。 这些描述了我们了解对象属性的关键点。 给定一组关键点,Unity会自动插值并生成这两个关键点之间将发生的移动。 继续前进时,请牢记此功能。

  • On the timeline above, there are numbers written depicting the time. Click on the number above the keypoint (diamond) at the end. A white line should appear over the keypoint. This denotes that the modification of that fraction of time will take place, which is under the white line. Now click on the red button to start recording the motion.

    在上面的时间轴上,写有描述时间的数字。 单击末尾关键点(菱形)上方的数字。 白线应出现在关键点上方。 这表示将对那部分时间进行修改,这是在白线下方。 现在单击红色按钮开始录制动作。

  • Using the transform tool, move the “Door” object in the Scene View such that it has reached an open state according to you. Press the Record Button again to stop recording. You can check the animation by pressing the play button that is besides the record buttom.

    使用变形工具,在“场景视图”中移动“门”对象,使其根据您的状态达到打开状态。 再次按录制按钮可停止录制。 您可以通过按下录制按钮旁边的播放按钮来检查动画。

  • Similarly create the “DoorClosed” animation. This is a task for the user.

    同样,创建“ DoorClosed”动画。 这是用户的任务。

4.使用Animator状态机 (4. Using the Animator State Machine)

Now that you have your moving doors, we have the problem of making them move according to our will. For this, we have to have an understanding of the Animator and what it actually does.

既然您拥有移动的门,那么我们就有使它们按照我们的意愿移动的问题。 为此,我们必须了解Animator及其实际功能。

Like it was mentioned above, the Animator takes care of the transferring of one Animation state to another. For exmple, imagine yourself playing a First Person Shooter game like PUBG or CS: GO. Here if you are only pressing W, the player character walks or jogs, but as soon as soon as shift is pressed in conjunction with the W key, the player seamlessly bursts into a sprint. This change from “Walk State” to “Sprint State” is what the Animator takes care of.

就像上面提到的那样,动画师负责将一个动画状态转移到另一动画状态。 例如,想象自己玩诸如PUBG或CS:GO之类的第一人称射击游戏。 在这里,如果您只按W,则玩家角色会走路或慢跑,但是一旦与W键一起按下shift键,玩家就会无缝地冲刺。 从“行走状态”到“冲刺状态”的这种变化是动画师所关心的。

Coming back to our door, if we open the Animator we will see various colored boxes with stuff written on them like “Entry”, “Any State”, “Exit”, etc. These are the various animation states.

回到我们的门,如果我们打开动画器,我们将看到各种彩色框,上面写有诸如“进入”,“任何状态”,“退出”等内容。这些是各种动画状态。

Among these you’ll find an orange arrow starting from Entry state to the DoorOpen state. This arrow (or any such arrow) depicts a transition from one animation state to another. Lets see what the various states signify.

其中有一个橙色箭头,从“输入”状态开始到“门打开”状态。 此箭头(或任何此类箭头)描述了从一种动画状态到另一种动画状态的过渡。 让我们看看各种状态的含义。

  • Entry: Entry refers to the state of animation when the scene first comes into existence.

    进入:进入是指场景首次出现时的动画状态。

  • Exit: This state is used to end the animation and begin again at the Entry state. To make it simple suppose your transition ends in state "foo". Try drawing a transition from "blablabla" to "Entry". You just can't.

    退出:此状态用于结束动画,并从进入状态再次开始。 为简单起见,假设您的转换以状态“ foo”结束。 尝试绘制从“ blablabla”到“ Entry”的过渡。 你就是不行

    Now If you really need to do that then that is when you use "Exit".

    现在,如果您确实需要这样做,那就是使用“退出”的时候。

  • Any State: Any State is a special state which is always present. It exists for the situation where you want to go to a specific state regardless of which state you are currently in. This is a shorthand way of adding the same outward transition to all states in your machine. Note that the special meaning of Any State implies that it cannot be the end point of a transition (i.e. jumping to “any state” cannot be used as a way to pick a random state to enter next).

    任何国家:任何国家都是始终存在的特殊国家。 它适用于无论您当前处于哪个状态都想要进入特定状态的情况。这是将相同的向外过渡添加到计算机中所有状态的一种简便方法。 请注意, 任何国家的特殊含义意味着它不能是一个过渡的终点(即跳转到“任何国家”不能被用来作为一种随机选择一个国家未来进入)。

Also you will see an arrow going from the Entry state to the DoorOpen state. This is not what we want. Here the door opens as soon as the scene starts. What we desire is that the door waits until we command it to move. So we need an “Idle” state, i.e. a state with no Motion attached to it.

您还将看到一个箭头,从“进入”状态变为“门打开”状态。 这不是我们想要的。 一旦场景开始,这里的门就会打开。 我们希望的是门一直等到我们命令门移动为止。 因此,我们需要一个“空闲”状态,即没有附加运动的状态。

  • To do this,right click on the Animator panel space and from the drop down, select Create State>Empty.

    为此, 请在Animator面板空间上单击鼠标右键,然后从下拉菜单中选择Create State> Empty

  • Now rename this “New State” state to “Idle” (do it yourself).

    现在,将此“新状态”状态重命名为“空闲”(自行完成)。

  • Now we need Idle to be the Default state (state transitioned to after Entry). TO do this right click on Idle and select the Set as Layer Default State

    现在我们需要将Idle设置为Default状态(Entry之后转换为State)。 为此,请右键单击“空闲”,然后选择“ 设置为图层默认状态”

Now for the transitions. Transitions refer to the transference of control from one state to the next. The arrow in orange that you see represents a transition.

现在开始过渡。 过渡是指控制权从一种状态转移到另一种状态。 您看到的橙色箭头表示过渡。

To create a transition, right click on the initial state> from the drop down select Make Transition>Click on the next state.

要创建过渡,请右键单击初始状态>然后从下拉菜单中选择进行过渡>单击下一个状态。

So try to create a working state diagram yourself and check it whether it is correct or not with the image below.

因此,请尝试自己创建一个工作状态图,并使用下图检查它是否正确。

Its not over yet. Here if you press play, the door opens and closes automatically. This is because our transitions are condition-less. Condition-less transitions occur as soon as the initial state has finished playing its animation once. We need control here. So we apply conditions to the transitions.

还没结束。 在这里,如果您按播放,门将自动打开和关闭。 这是因为我们的过渡是无条件的。 一旦初始状态完成播放其动画一次,就会发生无条件转换。 在这里我们需要控制。 因此,我们将条件应用于过渡。

To apply conditions, we require to set a parameter which toggles the door open or closed. To do this :

要应用条件,我们需要设置一个参数来切换门的打开或关闭状态。 去做这个 :

  • select the Parameter tab from the top left corner of the Animator panel.

    从“动画器”面板的左上角选择“ 参数”选项卡。

  • Click on the + icon below and select the Boolean option from the drop down list.

    单击下面的+图标,然后从下拉列表中选择布尔选项。

  • Rename it to “isDoorOpen” (do it yourself).

    将其重命名为“ isDoorOpen”(自己动手做)。

  • We select a boolean as it will be easy to depict the open and closed states of the door using it.

    我们选择一个布尔值,因为使用它可以轻松描述门的打开和关闭状态。

Now to apply the conditions to the transitions:

现在将条件应用于过渡:

  • Select a transition by clicking on the arrow.

    通过单击箭头选择一个过渡。

  • In the Inspector panel, click on + in the Conditions option.

    在“检查器”面板中,单击“条件”选项中的+。

  • Set the value of the condition acoordingly.

    相应地设置条件的值。

The value of the transition 1, 2, and 3 for “isDoorOpen” are true, false and true respectively.

“ isDoorOpen”的过渡1、2和3的值分别为true,false和true。

Hence we are done with setting up our conditions. We will be triggering these transitions via code.

因此,我们已经完成了设置条件的工作。 我们将通过代码触发这些转换。

5.编写代码 (5. Writing the Code)

  • Create an empty object called “Door Manager” and add a new C# script to it called “DoorManagerScript”.

    创建一个名为“ Door Manager”的空对象,并向其添加一个名为“ DoorManagerScript”的新C#脚本。

  • To add the script, select Add Component > New Script > Name the script “DoorManagerScript” > Press Create and Add

    要添加脚本,请选择添加组件 >新建脚本>将脚本命名为“ DoorManagerScript”>按创建并添加

  • In the script, type the following code and save it:

    在脚本中,键入以下代码并保存:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class DoorManagerScript : MonoBehaviour
{public Animator anim;private bool trigger;void Start(){anim.SetBool ("isDoorOpen", false);trigger = false;}void Update(){trigger = anim.GetBool ("isDoorOpen");if(Input.GetKeyDown (KeyCode.Space)){if(!trigger){anim.SetBool ("isDoorOpen", true);}else {sanim.SetBool ("isDoorOpen", false);}}}
}

6.穿过门并到达另一侧 (6. Through the door and to the other side)

Well I would like to congratulate you on creating your first moving object in Unity. And what’s more it works as per your command! Great job. This was just a glimpse of the power of the Mechanim system can do if its in your capable hands.

好吧,我谨祝贺您在Unity中创建了第一个移动对象。 而且,它还可以按照您的命令运行! 很好。 这只是Mechanim系统的强大功能的一瞥​​,只要它掌握在您的手中。

So press play and see the magic happen when you press the space bar.

因此,按播放键,然后按空格键即可看到魔术发生的情况。

翻译自: https://www.studytonight.com/game-development-in-2D/animation-animator

unity3d 动画制作

unity3d 动画制作_Unity 3D中的动画和动画制作相关推荐

  1. html画一个word怎么实现,word怎么制作流程图 Word中如何快速高效的制作流程图

    企业回可以使用亿图图示(Edraw Max)来设计流程图.亿图流程图制作软件可以用于绘制各种流程图,跨平台,云储存,分享功能的专业流程图制作软件.操作简单,功能强大,非常容易实现可视化.分析和交流复杂 ...

  2. android窗口退出动画,如何在Android中为弹出窗口制作动画

    PopupWindow自定义布局更方便,并且显示位置自由,没有任何限制.使用下面的代码并享受动画.在此动画中,使用底部滑入和滑出,但是您只能更改滑入/滑出动画,并根据您的动画对应用程序中的任何位置进行 ...

  3. java 图片动画_java在窗口中添加图片做动画,怎么一闪一闪的?

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 视频来自:优酷 在java中添加图片做动画效果,怎么一闪一闪的运动啊?怎样才能让它不闪的连续运动呢? 下面是代码,代码项目project里有两个类,一个是 ...

  4. android 转场动画 监听,Android 中的转场动画及兼容处理

    Android 中的动画有很多,除了在一个界面上使用帧动画.属性动画将一个或多个 View 进行动画处理以外,还可以用于两个界面之间过渡.跳转.在 Android 5.0 之前,我们已经有了 over ...

  5. 计算机3d 游戏制作,揭秘3D电影、游戏角色的制作过程!

    原标题:揭秘3D电影.游戏角色的制作过程! 从来没有接触过建模的小白们是否都很好奇,3D电影.游戏角色是怎样做出来的呢?比如说<捉妖记>里的胡巴.今年大火的国漫<哪吒>,< ...

  6. unity3d技术摄像头跟随_unity 3d 中摄像头跟随人物移动总结

    学习unity 也已经有比较成的一段时间了,但还是菜鸟级别啊,一直苦于没有师傅,如果能找到个好的师傅带领我,估计像我这样的石头也已经是很牛的人了吧,哈哈.... 好了 不开玩笑了.  在游戏中人物会移 ...

  7. android 折纸动画,如何在Android中实现折纸动画

    受到iOS版的启发,在最近的项目中,我们决定在打开列表元素时实现一个类似风格的动画效果.起初,我们试图使用一个现有的实现--android-flip, 通过OpenGL渲染动画--在***的Andro ...

  8. 小地图的制作,游戏中的导航仪,minimap制作(继续我们的仙剑demo)

    我们继续白天的话题,白天列出了还有哪些东西需要后续的讲解,今晚我们就来讨论下小地图,说实话,小地图这个概念在u3d里面因为有透视相机的出现,制作起来简单的不能再简单了,看看代码 /// <sum ...

  9. 制作一个状态栏中跑马灯效果_snapseed制作“照片中的照片”画中画效果的方法...

    用摄影修图软件做出"我拿着我的照片给你看"的效果,用snapseed在手机上修图就可以实现,用"双重曝光"+"图层蒙版"的方式,非常容易做到 ...

最新文章

  1. checkbox点击切换选中状态
  2. 测试php语句执行时间
  3. 初探DispatcherServlet#doDispatch
  4. 颠覆:链表在删除和插入的效率一定优于数组吗?
  5. fnCustomBootTask for local sandbox 在何处赋值
  6. 设计模式六大原则(3)——依赖倒置原则
  7. Android之 RecyclerView,CardView 详解和相对应的上拉刷新下拉加载
  8. html标签之img,input标签
  9. jQuery地图插件-jqvmap
  10. 5 html 根据手机转动而转动_最全的全景照片拍摄方法合集,手机也能拍哦
  11. mysql教程datetime_Mysql中的Datetime与Timestamp不同之处
  12. matlab7.0工具箱,matlab6.5+gaot工具箱和matlab7.0自带工具箱的效果一样吗?
  13. vb caption 换行
  14. MAC版WORD使用EndNote之后每次打开都显示域代码解决方法
  15. 调研之路 --- MXF
  16. 【快应用】十大手机厂商共推快应用标准
  17. 自定義ListActivity(一)
  18. jstat gc命令详解
  19. arduinopn532模块_零知开源分享-使用PN532串口NFC模块读写NFC卡片
  20. BUUCTF Rabbit

热门文章

  1. azkaban任务状态一直在Preparing状态不能更新的解决办法
  2. 三类6种地图可视化软件测评,最好用的工具居然是它
  3. Gym - 101606L Lizard Lounge——LIS
  4. Win系统上最好用的epub阅读器
  5. java计算抛物线的标准方程_抛物线方程公式大全_抛物线的四种标准方程_抛物线公式_抛物线方程及图像_高中数学知识点总结网...
  6. Gitee+Typora+PicGo+脚本
  7. GPS与GPRS模块功差之千里
  8. 05-SA8155 QNX通过QUB配置GPIO/INT/SPI/I2C/SPI等
  9. jQuery--复制节点clone()详解
  10. 280049_CAN 模块