B2 中上級 3307 タグ追加 保存
As a general rule, if you're going to have
moving game objects in your game
you should make sure that they are
rigidbody objects.
Rigidbodies are components that allow
a game object to be effected by physics.
They allow the object to fall under gravity,
and have physics properties such as mass,
drag and velocity.
When we add a rigidbody component
to a game object we often then refer to it
as a rigidbody object.
A rigidbody component is required for any physics
based interaction, and the game object
must also have a collider attached
in order to interact with other physics objects.
Without a rigidbody our power cube will
simply hover in mid air.
But let's see what happens when we add one.
Like any other component it can be added
using the Add Component button at
at the bottom of the inspector, or from
the 'Component' top menu.
You will find it under the Physics section.
Now our object falls under gravity
and can be controlled by the physics engine
and any forces that are applied to it.
Rigidbodies have numerous options.
Firstly there are settings to control the mass,
drag and angular drag of the game object.
The mass of the object effects how collisions
are treated with the object.
Game objects with a higher mass will react
less when collided with a lower mass
game object.
The drag of a game object effects how
quickly it will slow down without
other interactions.
Think of it like air resistance.
It's used to determine the rate of a loss
of linear velocity.
Similarly, angular drag effects how
quickly the game object will slow it's
angular velocity, i.e. how
fast it is rotating.
So for example if you're adding torque
to the object to rotate it,
the angular drag will create resistance
to this force. The next option is
whether or not the game object is
effected by gravity.
By enabling this checkbox we use gravity.
Settings for gravity can be seen in the
Edit - Project Settings - Physics area of Unity.
As you can see it's a 3 dimensional vector
which by default has a real world
value of -9.81.
Because you can customise it globally here
you could also create interesting effects
Such as low gravity for a platformer
or even setting it to a different axis
as part of a puzzle game.
For example, let's add gravity to the
Z axis by a value of 5.
And now the power cube is pulled towards
towards the global Z axis.
The Is Kinematic setting effects whether
or not a rigid body will react to physics.
Ordinarily when a scene begins, all static
geometry, meaning any non-rigidbody objects
are checked once by the physics engine
and not checked again for efficiency.
However when you move a static object
the physics engine must re-check all other
static objects for the sake of accuracy,
and this can be expensive to performance.
To avoid this, Kinematic rigidbody objects can be used
and moved via their transform
by using the Translate function.
This means that you can have physics objects
that effect others but are not effected themselves.
An obvious example of this would be the
paddle in a Pong or Breakout style game.
In this example our rigidbody power cube
has Use Gravity checked.
When we press play, the object falls to the ground.
We also have our round prop samoflange ball
object, which has a similar component setup.
If the power cube does not have gravity
then it will not fall under it, but it will
be effected by other objects.
If we don't want it to be effected by other
objects we can use Is Kinematic.
And as stated we can also move the object
via it's transform. So we'll make use of
this simple script, which uses the
translate function to move it via it's
forward direction every frame.
And as you can see, the object still
interacts with the others but remains a
rigidbody, so is constantly informing
the physics engine of it's location
and not forcing the physics engine
to re-evaluate the entire scene.
The Interpolate and Extrapolate settings
are there to solve jittering.
If you experience slight movement of your
object when moving it via it's rigidbody,
make use of the interpolate setting in order to
smooth the transform movement based on the
previous frame. And the extrapolate setting
to smooth based on a predicted
location in the next frame.
The next setting is for the type of
collision detection. We have Discrete,
Continuous and Continuous Dynamic.
The default is discrete and unless you
have any problems you should use discrete.
Continuous is for fast moving objects
that are interacting with static geometry.
And continuous dynamic is for fast moving
objects that are interacting with other
dynamic objects.
Finally the constraints section of the
rigidbody component allow you to
constrain movement or rotation of the object
by physics. For example, if you
had a Tetris style game you might not
want the cubes of your game to rotate
as they fell in to place. You could constrain
this using the rotation constraints here.
In this example our power cube is
falling on to the workbench. It's a rigid
body that has Use Gravity checked.
And as standard it falls like this.
If we didn't want it to rotate as it falls
we can freeze the rotation within the constraints.
And now when it falls, no rotation.


物理対象-Unity公式チュートリアル (Physics Objects (Rigidbodies) - Unity Official Tutorials)

3307 タグ追加 保存
朱瑛 2014 年 5 月 2 日 に公開
  1. 1. クリック一つで単語を検索


  2. 2. リピート機能


  3. 3. ショートカット


  4. 4. 字幕の表示/非表示


  5. 5. 動画をブログ等でシェア


  6. 6. 全画面再生


  1. クイズ付き動画


  1. クリックしてメモを表示

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔