Skip to content

Latest commit

 

History

History
83 lines (49 loc) · 5.75 KB

File metadata and controls

83 lines (49 loc) · 5.75 KB

Physics

Physics in Unity might include:

  • Rigidbodies
  • Colliders
  • Kinematics
  • Triggers

car physics

Figure 1: Making Custom Car Physics

3D Physics

In this setting, 3D physics refers to the properties of objects and how they respond to forces. Unity's built-in physics engine has a breadth of tools that ensure objects can interact with other objects by approximating natural forces, such as gravity, velocity, acceleration, and friction. Figure 1 shows the properties of Unity's 3D physics engine.

Figure 1: Unity's physics properties

Gravity has a more significant effect on objects with greater mass. Drag dampens linear velocity, and angular drag affects the rotational force of angular velocity. Friction is a resistive force.

Physics Materials

Unity uses specialised physic materials to adjust the physical collider properties (such as friction and bounciness) of the GameObjects to which they're assigned.

Rigidbody

A RigidBody, shown in Figure 2, below, is the main component that enables physical behaviour for a GameObject. A RigidBody is a term borrowed from the real world - it is an idealised object that does not deform under the influence of external forces; instead, it maintains its shape and size, making it ideal for analysing mechanical systems in physics and engineering and also for modelling idealised physical systems in Unity. A Unity RigidBody also detects and resolves collisions between colliders (see below).

Figure 2: RigidBody

Typically, Rigidbody components are used to add physics behaviour to GameObjects. It is also important to note that for Unity to register collisions between 2 GameObjects with colliders, at least one of them must have a Rigidbody component.

Since a Rigidbody component is responsible for the movement of the GameObject to which it is attached, unless the RigidBody is Kinematic (see below), you shouldn't try to move the GameObject by changing its Transform properties in a script (we'll look at scripting later in the module). Instead, you should apply forces to push the GameObject and let the physics engine calculate the results.

Kinematics

Kinematics is the study of the motion of mechanical points, bodies and systems without consideration of their associated physical properties and the forces acting on them.

When something is Kinematic in Unity, the physics behaviour of its RigidBody component is disabled, so it does not get affected by external forces; a Kinematic RigidBody can still push another RigidBody, but it cannot be pushed.

You will not be able to manipulate a kinematic RigidBody by using rigidbody.AddForce or rigidbody.velocity in a script (we'll look at scripting later). The only 2 ways to move a kinematic Rigidbody are:

  1. By applying an animation
  2. By translating their position in code with Transform or MovePosition etc.

However, a kinematic RigidBody still collides with other rigid bodies.

These properties make them ideal for projectiles, platforms and elevators, because you want such things to maintain a path independent of physical forces (like gravity), while still having the ability to transport that which they've collided (such as a player controller).

Colliders

Colliders allow Unity to register when two objects interact. They define the physical collision shape of a GameObject, such that, a GameObject will react to incoming collisions if it has a RigidBody component that is associated with one or more Collider components. Colliders are invisible and do not need to match the shape of their associated GameObject mesh. The primitive colliders, Box Collider, Sphere Collider and Capsule Collider are the most straightforward and least processor-intensive.

Static Colliders

GameObjects with a collider (but no RigidBody) count as static obstacles that never move. However, they can still interact with other GameObjects that have a RigidBody and a Collider, so they are useful for massive immovable objects like the ground or the first floor of a building.

Triggers

Triggers function similarly to colliders. However, when triggers interact with colliders, they are ignored by the physics engine. Instead, they can execute scripts, which means they are useful for triggering all types of events; examples are some actions when a collider enters an area, tutorial messages or cutscenes. You will take advantage of triggers later in the course.

External Links

Links