Rigidbody vs TranslateWhich Should You Use?

Author Waldo
Published October 19, 2018

In this video I go over a few methods on how to move a player or an object around the screen. I think share my thoughts on which method is best for each use.

Video Walkthrough

  • 0:28 - Moving An Object Using Translate
  • 2:20 - Problems with using Translate
  • 2:50 - Using RigidBody for Physics & Collisions
  • 5:00 - 3 Ways to Move An Object with RigidBody
  • 5:10 - Using AddForce()
  • 6:15 - Using Velocity
  • 7:05 - Using MovePosition

Source Code for Translate

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

public class translate : MonoBehaviour {
    public float speed = 10.0f;

    // Update is called once per frame
    void Update () {
        moveCharacter(new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")));

    }
    void moveCharacter(Vector2 direction){
        transform.Translate(direction * speed * Time.deltaTime);
    }
}

Source Code for RigidBody

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

public class rbmovement : MonoBehaviour {
    public float speed = 10.0f;
    public Rigidbody rb;
    public Vector2 movement;

    // Use this for initialization
    void Start () {
        rb = this.GetComponent<Rigidbody>();
    }
    
    // Update is called once per frame
    void Update () {
        movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
    }
    void FixedUpdate(){
        moveCharacter(movement);
    }
    void moveCharacter(Vector2 direction){
        //insert one of the 3 types of movement here
    }
}

To Move With AddForce()

void moveCharacter(Vector2 direction){
    rb.AddForce(direction * speed);
}

 

To Move With Velocity

void moveCharacter(Vector2 direction){
    rb.velocity = direction * speed;
}

 

To Move With MovePosition

void moveCharacter(Vector2 direction){
    rb.MovePosition((Vector2)transform.position + (direction * speed * Time.deltaTime));
}

This tutorial is sponsored by this community

In order to stick to our mission of keeping education free, our videos and the content of this website rely on the support of this community. If you have found value in anything we provide, and if you are able to, please consider contributing to our Patreon. If you can’t afford to financially support us, please be sure to like, comment and share our content — it is equally as important.

Join The Community

Discussion

Browse Tutorials About