Using Rigidbody to add force.
Objective: Using Rigidbody to add force.
I have a script called Apply Force, which is attached to the box.
This box has rigidbody attached to it, since we will use this rigidbody to add force to this box.
Create a Rigidbody reference and cache it in the start method.
Create a float variable called forceValue, and initialize it to 10.
To add force, we use Rigidbody.AddForce: This method takes a Vector3 and ForceMode.
If we play now the box will be pushed in opposite direction of its relative Z axis.
Note:AddForce push Box in World space if you looked at gizmo z-axis is point at us from the screen.
To move this object relative to its axis, we need to use AddRelativeForce.
Understand Force Mode.
ForceMode.Force take into account the mass of the object, so when pushing a heavy object, it won't move at a constant speed at all times. Speed builds up in time according to the mass of an object, and it will need much force to move it.
ForceMode.Impulse, this will use Instant force but it will consider mass of the object much force require to push the object.
ForceMode.Acceleration ,this will move the object in constant speed without looking of mass different of object ,but it require higher force to push object.
ForceMode.ChangeVelocity: This will add an Instant Change of Velocity without taking account of mass.
RigidBody.AddTorque is similar to those above, I will use AddTorque here with its variable.
Let's see the result.
See you in the next one.