[Unity] Rigidbody simple manual

3 minute read


This article is a brief description of the ** beginner ** Rigidbody, picking up the ones you use most often.
The meaning of personal memos is strong, so if you want to know more details, please go to the official reference. ](Https://docs.unity3d.com/ScriptReference/Rigidbody.html)
I plan to write a separate article for items not listed below.

What is Rigidbody?

In the Official Manual, it is described as follows.

Rigidbody allows you to control game objects by physics. By applying force or torque to the rigid body, you can move the object realistically. Rigid bodies must be added to game objects in order to exert gravity effects, use scripts to force them, and interact with other objects through the NVIDIA PhysX physics engine.

The ** mass ** of the object. Set according to the image of the object (20 for iron balls, 0.01 for wings, etc.). If you think heavy things will fall fast, be careful because it’s a big mistake.
The ** resistance ** of the object. If you increase the value, the resistance will increase and the object will slow down. By adjusting this, you can express things like in the water.
** Rotational resistance ** of an object. If you don’t know the rotation resistance etc., remember it with the rotation version of drag. Effective when you want to slow down the rotation of gears.
** Presence / absence of gravity ** can be set. Set to false if you want to express outer space.
** Whether to behave physically. ** If set to true, it will not behave physically. It’s easy to think that you shouldn’t use the rigidbody itself, but it’s useful when you want to create a doll-like object that suddenly stops moving.
** Interpolation ** function of operation. Since the timing when Update () is called and the timing when FixedUpdate () that performs physics is called do not always match, the movement becomes stiff. Interpolate is calculated using the speed of the previous frame. Extrapolate predicts the position of the next frame from the current speed and performs extrapolation. Since the calculation process is heavy, it is good to set only the main character that follows with the camera.
Movement and rotation on any axis can be controlled. Although it is a 3D space, it can be used when expecting 2D-like behavior.

Public Methods
Only useful methods, but since it is a simple reference, I will describe the basic ones.
AddForce(Vector3 force, ForceMode mode)
A method of applying force. Specify the force vector with force.
The Force Mode is explained below.

** Force Mode type **
There are four modes.

Behavior close to the laws of physics.
** a = F / m (acceleration = force / mass)**
Calculate with.
It is good to use it for an object that accelerates by gradually applying force. Default if ForceMode is not specified.

Mass-ignoring version of the above Force.
** a = F (acceleration = force)**
Therefore, use it when you want to gradually accelerate any weight.

Instantaneous force that ignores acceleration.
** v = F / m (speed = force / mass) **
Calculated with. Used when only one force is generated. Personally, I think it works best with games.

Mass-ignoring version of Impulse above.
** ```v = F (speed = force) ` **
Therefore, it is used when you want to blow it off regardless of the mass.

AddTorqueVector3 torque, ForceMode mode)
Apply ** torque ** to the object. If you don’t know the torque, please click here. ](Https://www.adrec-jp.com/products/about_torq.html)
Used when you want it to rotate physically.

MovePosition(Vector3 position)
Move the position of the object coordinately. If you want to move an object that uses rigidbody regardless of physical behavior, MovePosition is lighter than transform.position.

MoveRotation(Quaternion rot)
Rotate the object. A rotated version of Move Position.


I said it as a memo at the beginning, but it has become a level that I will never forget.
I hope that beginners who say that the official reference is messy and hard to see will see it as an introduction.