Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Turret : MonoBehaviour {
- public Transform target;
- public float rotateSpeed = 45;
- // Update is called once per frame
- void Update () {
- var localTarget = transform.InverseTransformPoint(target.position);
- localTarget.y = 0;
- var targetRot = transform.rotation * Quaternion.LookRotation( localTarget );
- transform.rotation = Quaternion.RotateTowards( transform.rotation, targetRot, Time.deltaTime * rotateSpeed );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment