How to make the objects fall in Unity

There are a lot of ways how to make the objects fall in Unity. In our game we are using two of them.

Why did the left timer hit the ground first? After all the red watch was a little higher than the blue one. Thanks to Physics! And artificial Gravitational pull.

While the left watch was taking on the speed and falling faster in every millisecond (for example like cars do) the right one had a steady linear falling speed. You can use this in a lot of ways.

Why don’t we stick with one falling type? Because we wanted to differentiate the two falling types for different objects.

If you want to use the right way of objects falling (Blue Timer) you can use this script below and assign it to the object.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TimerFall : MonoBehaviour {

  public float fallSpeed = 40.0f;      //How fast should the object fall

  // Update is called once per frame
  void Update () {

      transform.Translate(Vector3.down * fallSpeed * Time.deltaTime, Space.World);
  }
}

As you see. It’s not much. In fact we need only to write two lines of code. Variable initialization which is responsible for the speed of falling and the transform.Translate function. What does the function do? It just changes the position of an object in the Scene. That’s all.

In the left example (Red Timer) we don’t any code at all!

You just need to use build-in function called Rigidbody 2D. On the object “Add Component” => Physics 2D => Rigidbody 2D

What kind of numbers (variables) do i need to put there to make the physics work? It depends on what do you want to achieve. I am focusing most of the time on “Mass” and Gravity Scale. Sometimes i change the Linear Drag and Angular drag. But not so often.

Here are the variables used in the example above:

Well that’s all you need to know. Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *