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 FollowPlayer : MonoBehaviour
- {
- public float moveSmoothness;
- public float rotSmoothness;
- public Vector3 moveOffset;
- public Vector3 rotOffset;
- public Transform player;
- private void FixedUpdate()
- {
- FollowCar();
- }
- void FollowCar() {
- HandleMovement();
- HandleRotation();
- }
- void HandleMovement()
- {
- Vector3 targetPos = new Vector3();
- targetPos = player.TransformPoint(moveOffset);
- transform.position = Vector3.Lerp(transform.position, targetPos,moveSmoothness * Time.deltaTime);
- }
- void HandleRotation()
- {
- var direction = player.position - transform.position;
- var rotation = new Quaternion();
- rotation = Quaternion.LookRotation(direction + rotOffset, Vector3.up);
- transform.rotation = Quaternion.Lerp(transform.rotation, rotation, rotSmoothness * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement