unity中物理组件的添加_Unity Engine物理组件
unity中物理组件的添加
Unity Engine物理组件 (Unity Engine Physics Components)
One of the core foundations of most games, whether they be 2D or 3D, is the Physics involved in them. Physics need not be complicated stuff like wave equations and fluid dynamics. Even the most basic stuff that you do in making a game involves physics.
不管是2D还是3D,大多数游戏的核心基础之一就是物理原理。 物理学不需要像波动方程和流体动力学这样的复杂事物。 甚至您制作游戏中最基本的内容都涉及物理。
For example, moving the player generally involves either adding a force on the object that is the player, or displacing it by a certain amount. Making it float or drown in water, or just slide down slopes is also involved with how physics work.
例如,移动播放器通常涉及在作为播放器的对象上施加力,或将其移动一定量。 使它漂浮或淹没在水中,或者只是滑下斜坡也与物理学的工作方式有关。
Physics in Unity, and in general game design, are really important. Most of the time, it's the physics of a game which cause "bugs"
or "glitches"
. Some examples of these would be OoBs (Out of Bounds) and clipping errors.
Unity中的物理以及一般游戏设计中的物理非常重要。 在大多数情况下,游戏的物理原因会导致"bugs"
或"glitches"
。 其中一些示例是OoB(越界)和裁剪错误。
In this section, we'll be looking at how we can add physical properties to objects in our game, and how we can make them work the way we want them too. We'll also learn more about referencing objects and the magic of public.
在本节中,我们将研究如何向游戏中的对象添加物理属性,以及如何使它们也按我们希望的方式工作。 我们还将学习有关引用对象和公共魔术的更多信息。
Unity:从2D物理开始 (Unity: Starting with 2D Physics)
As the name implies, 2D means working in two dimensions. As such, we don't really care about what's going on in the third dimension (or the Z-axis.) As far as we're concerned, we only need to care about the X axis (what's going on horizontally) and the Y axis (what's going on vertically).
顾名思义,二维意味着在二维中工作。 因此,我们实际上并不关心第三维(或Z轴)上发生的事情。就我们而言,我们只需要关心X轴(水平上进行的事情)和Y轴(垂直方向)。
In fact, here's a little thing you can try out before we get started. In Unity, try clicking on the 2D button on the top-left of the scene view.
实际上,您可以在开始之前尝试一下这一点。 在Unity中,尝试单击场景视图左上角的2D按钮。
What you'll see is something like this:
您将看到的是这样的:
You'll notice that Unity is actually just making us think that we're working in 2D when in reality we're actually just making a flat 3D game! We can actually use this trick that Unity uses to our own advantage, as we'll see later on when we discover Lighting effects.
您会注意到,Unity实际上只是让我们认为我们正在2D工作,而实际上我们实际上只是在制作平面3D游戏! 实际上,我们可以利用Unity使用的这一技巧来发挥自己的优势,正如我们稍后将在发现Lighting效果时看到的那样。
Alright, time to get started. Here's what we'll be working with:
好了,该开始了。 这是我们将要处理的内容:
- Vectors 向量
- Rigid-bodies and Forces 刚体和力量
- Colliders and Collisions 撞机和碰撞
- Your first game 你的第一场比赛
We will explain what Unity vectors and forces are here, and from the next lesson onwards, we will start off with Rigidbodies and Collisions.
我们将在这里解释什么是Unity向量和力,从下一课开始,我们将从Rigidbodies和Collisions开始 。
In Unity, we have two scripting classes, named Vector2 and Vector3(Actually, there's a Vector4 as well, but we're not really concerned with that for the time being). Vector2 and Vector3 are what you can call containers
for a number of numeric values, most often floating point values, represented by the number on the end. So, Vector2 is a container for two individual values, and Vector3 is a container for 3 values. When we work in Unity2D, the Vector2 class becomes prominent, although Vector3 still has some uses.
在Unity中,我们有两个脚本类,分别是Vector2和Vector3 (实际上,也有Vector4,但是暂时我们并不在意)。 Vector2和Vector3是您可以调用的containers
用于包含许多数字值,通常是浮点值,由末尾的数字表示。 因此, Vector2是两个单独值的容器,而Vector3是三个值的容器。 当我们在Unity2D中工作时,尽管Vector3仍然有一些用途,但Vector2类变得很重要。
Since this might be a bit confusing for some readers, let's understand with an example. Let's say we have the position of an object, say Mr. Star. His position in the 2D game world is defined by an X value (that is, horizontally) and a Y value (vertically).
因为这可能会使一些读者感到困惑,所以让我们看一个例子。 斯塔先生说,假设我们有一个物体的位置。 他在2D游戏世界中的位置由X值(即水平)和Y值(垂直)定义。
In writing code for Unity, instead of making two separate values for the position of Mr. Star, we use a Vector2 which holds two variables instead. These variables can either be defined, or can be set to other user-defined variables.
在为Unity编写代码时,我们没有使用两个保存两个变量的Vector2来代替Star先生的位置设置两个单独的值。 这些变量可以定义,也可以设置为其他用户定义的变量。
NOTE: Don't worry about where to write your C# code, we will show you how to add your own scripts soon.
注意:不用担心在哪里编写C#代码,我们将向您展示如何尽快添加自己的脚本。
Of course, a Vector2 isn't really limited to defining a position. A Vector has its best use whenever you're dealing with values that modify (or define) the location, rotation or direction of something.
当然, Vector2并不仅限于定义位置。 每当您处理修改(或定义)某物的位置,旋转或方向的值时,Vector便会发挥其最佳作用。
Note: If you didn't install Visual Studio when you installed Unity, your scripts will most likely open in Unity's default interface, MonoDevelop. Don't worry if code looks different than yours in color or something like that; as long as you're following what's going on, you'll be fine.
注意:如果在安装Unity时未安装Visual Studio,则脚本很可能会在Unity的默认界面MonoDevelop中打开。 如果代码看起来与您的颜色或类似内容有所不同,请不要担心; 只要您跟踪发生的事情,就可以了。
翻译自: https://www.studytonight.com/game-development-in-2D/2D-physics-components
unity中物理组件的添加