using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShipFollower : MonoBehaviour {

	public Vector3 Offset;
	public Transform Target;
	public float LerpSpeed = 0.5F;

	public bool FollowRotation = true;

	// Use this for initialization
	
	
	// Update is called once per frame
	void Update () {
		transform.position = Target.transform.position+getOffset();
		if(FollowRotation) {
			MapRotation();
		}
	}

	Vector3 getOffset() {
		Vector3 res = Vector3.zero;

		res += Camera.main.transform.right*Offset.x;
		res += Camera.main.transform.forward*Offset.y;
		res += Camera.main.transform.up*Offset.z;
		

		return res;
	}

	void MapRotation() {
		Vector3 newRot = transform.rotation.eulerAngles;
		
		newRot.y = Quaternion.LookRotation(Target.forward,Vector3.up).eulerAngles.y;
		transform.rotation = Quaternion.Euler(newRot);

	}
}
