Translate and Rotate
Tutorial
·
Beginner
·
+10XP
·
5 mins
·
(2756)
Unity Technologies

How to use the two transform functions Translate and Rotate to effect a non-rigidbody object's position and rotation.
This tutorial is included in the Beginner Scripting project.
Previous: Activating GameObjects
Next: Look At
Languages available:
1. Translate and Rotate
TransformFunctions
using UnityEngine;
using System.Collections;
public class TransformFunctions : MonoBehaviour
{
public float moveSpeed = 10f;
public float turnSpeed = 50f;
void Update ()
{
if(Input.GetKey(KeyCode.UpArrow))
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.DownArrow))
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
}
}