Last active
July 20, 2017 15:09
-
-
Save KRNKRS/d12054bc26a10e48203df2a7f08dcdb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CameraOffset : MonoBehaviour | |
{ | |
public float moveSpeed = 2; | |
private GameObject playerObj; | |
private Vector3 offset; | |
void Awake() | |
{ | |
playerObj = GameObject.FindGameObjectWithTag("Player"); | |
} | |
// Use this for initialization | |
void Start() | |
{ | |
offset = this.transform.position - playerObj.transform.position; | |
} | |
// Update is called once per frame | |
void FixedUpdate() | |
{ | |
var nowPosition = this.transform.position; | |
var targetPosition = playerObj.transform.position + offset; | |
var newPos = Vector3.Lerp(nowPosition, targetPosition, moveSpeed * Time.deltaTime); | |
this.transform.position = newPos; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment