Firstborn/Assets/PivecLabs/MiniMap/Scripts/orbitPlayer.cs

35 lines
756 B
C#
Raw Normal View History

namespace PivecLabs.Minimap
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class orbitPlayer : MonoBehaviour {
public Transform PlayerTransform;
private Vector3 cameraOffset;
public float rotateSpeed = 5.0f;
void Start () {
cameraOffset = transform.position - PlayerTransform.position;
}
void LateUpdate () {
Quaternion camTurnAngle =
Quaternion.AngleAxis(Input.GetAxis("Mouse X") * rotateSpeed, Vector3.up);
cameraOffset = camTurnAngle * cameraOffset;
Vector3 newPos = PlayerTransform.position + cameraOffset;
transform.position = Vector3.Slerp(transform.position, newPos, 0.5f);
transform.LookAt(PlayerTransform);
}
}
}