cdiego

Unity3D Rotar para mirar objetos - slerp quaternion

Nov 25th, 2014
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Mirar : MonoBehaviour {
  5.  
  6.     public Transform Objetivo;
  7.     public float velocidad;
  8.  
  9.     void Start () {
  10.    
  11.     }
  12.    
  13.     void Update () {
  14.         //Obtener la direccion, restando las posiciones (Vector3)
  15.         Vector3 direccion = transform.position - Objetivo.position;
  16.         //Crea la rotacion en base a la direccion
  17.         Quaternion rotacion = Quaternion.LookRotation (direccion);
  18.         //Aplicar la rotacion a nuestro objeto
  19.         transform.rotation = Quaternion.Slerp (transform.rotation, rotacion, velocidad * Time.deltaTime);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment