Translate and Rotate

Evidence

Script

using System.Collections;
using UnityEngine;

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);
    }
}

Screencast

What I Learned

For this project I learned how to make an object move through a script. The object moves by pressing the arrow keys, and the turn speed and move speed can both be altered in either the script or the hierarchy view. A problem I had to solve was making sure I got every detail of the code right, as there are a lot of pieces for this specific tutorial.

Leave a Reply

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