Skip to content

Instantly share code, notes, and snippets.

@damiancastelao
Created January 24, 2024 06:21
Show Gist options
  • Save damiancastelao/c884c58b7fb175c1fc319ba867746374 to your computer and use it in GitHub Desktop.
Save damiancastelao/c884c58b7fb175c1fc319ba867746374 to your computer and use it in GitHub Desktop.
Unity - Traslacion y Rotacion
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);
}
}
@damiancastelao
Copy link
Author

Si le aplicamos este script a un objeto, lo podremos trasladar en dirección Z y rotar en la direccion del eje Y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment