Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraController : MonoBehaviour {
- Transform player;
- Animator playerAnimator;
- Vector3 targetPosition;
- public Vector3 followOffset, idleOffset;
- public float maxCamSpeed;
- // Use this for initialization
- void Start ()
- {
- player = GameObject.FindGameObjectWithTag("Player").transform;
- playerAnimator = player.GetComponent<Animator>();
- transform.position = player.position - player.forward * idleOffset.z + player.up * idleOffset.y;
- }
- // Update is called once per frame
- void Update ()
- {
- if(playerAnimator.GetBool("isWalking"))
- {
- targetPosition = player.position - player.forward * followOffset.z + player.up * followOffset.y;
- }
- else
- {
- targetPosition = player.position - player.forward * idleOffset.z + player.up * idleOffset.y;
- }
- if ((targetPosition - transform.position).magnitude > maxCamSpeed)
- {
- transform.position += (targetPosition - transform.position).normalized * maxCamSpeed;
- }
- else
- {
- transform.position = targetPosition;
- }
- transform.LookAt(player.position);
- transform.position += (targetPosition - transform.position).normalized * maxCamSpeed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement