Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TrackingSystem : MonoBehaviour {
- public float speed = 20.0f;
- GameObject m_target = null;
- Vector3 m_lastKnownPosition = Vector3.zero;
- Quaternion m_lookAtRotation;
- // Update is called once per frame
- void Update ()
- {
- //This is short hand for if(m_target != null)
- if (m_target)
- {
- if (m_lastKnownPosition != m_target.transform.position)
- {
- m_lastKnownPosition = m_target.transform.position;
- m_lookAtRotation = Quaternion.LookRotation(m_lastKnownPosition - transform.position);
- }
- if (transform.rotation != m_lookAtRotation)
- {
- transform.rotation = Quaternion.RotateTowards(transform.rotation, m_lookAtRotation, speed * Time.deltaTime);
- }
- }
- }
- public void SetTarget(GameObject target)
- {
- m_target = target;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment