[Unity] Basic Movements

In most cases, you first need to get either transform variable or rigidbody variable of an object.

  • Transform.position
    *”transform” is a variable that refers to the transform of the object the script is attached to. No need to declare.
    ex) transform.position += new Vector3(1, 1, 1) * Time.deltaTime;
  • Transform.translate
    ex) transform.translate(new Vector3(1, 1, 1) * Time.deltaTime);
  • Rigidbody.velocity
    ex) public Rigidbody rb;
    rb.velocity = new Vector3(1, 1, 1);
  • Rigidbody.AddForce
    ex) public Rigidbody rb;
    rb.AddForce(new Vector3(1, 1, 1));
  • Vector3.MoveTowards
    ex) transform.position = Vector3.MoveTowards(transform.position, target.position, 2.0f);
In order for gameobjects to collide, both need to have colliders and at least one of them need to have rigidbody. 

In 2d development,

    Vector3 -> Vector2, Rigidbody -> Ridigbody2D

Scroll to Top