Colliders and Different Methods of Moving Objects in Unity

One problem with students starting to work with Unity is to understand when colliders work and when they do not work. This very simple demonstration shows how Physics::AddForce(), CharacterController:: SimpleMove() and Translate.Transform() behaves with colliders. Moving a GameObject using Physics and CharacterController based methods interacts with collisions whereas Transform::Translate() does not as seen in the video. Moreover, Translate does not work with MonoBehavior::OnTriggerEnter().


Physics::AddForce():

public class PhysicMove : MonoBehaviour {

	void Start () {
		rigidbody.AddForce (new Vector3 (100, 0, 0));
	}
}

CharacterController::SimpleMove()

public class Move : MonoBehaviour {

	public float speed;

	private CharacterController controller;

	void Start () {
		controller = GetComponent ();
	}
	
	void Update () {
		controller.SimpleMove (new Vector3 (1, 0, 0) * Time.deltaTime * speed);
	}
}

Transform::Translate()

public class MoveTranslate : MonoBehaviour {

	public float speed;

	void Start () {
		enabled = false;
	}

	void Update () {
		transform.Translate (new Vector3 (1, 0, 0) * Time.deltaTime * speed);
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s