Quantcast
Channel: Questions in topic: "follow"
Viewing all articles
Browse latest Browse all 536

2.5D Camera follow script

$
0
0
Hello guys, I've been making 2.5D game and I tried to create smooth camera follow script. I want camera to in front of the player, so he can see where he's going. I tried to add Vector 3 movedOffest as the offset for camera to be always in front or behind the player, but it's not smooth, it's realy laggy and I dont know how to fix it. ---------- My script using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFollow : MonoBehaviour { [Header("Camera Settings")] [SerializeField] private Transform target; [SerializeField] private float smoothSpeed; [SerializeField] private Vector3 offset; [SerializeField] private Vector3 movedOffest; private void Awake() { target = GameObject.FindGameObjectWithTag("Player").transform; } private void FixedUpdate() { Vector3 desiredPosition = target.position + offset; Vector3 smoothedPosition = Vector3.Slerp(transform.position, desiredPosition, smoothSpeed); if (Input.GetAxis("Horizontal") < 0) { transform.position = smoothedPosition - movedOffest; Debug.Log("Left"); } else if (Input.GetAxis("Horizontal") > 0) { transform.position = smoothedPosition + movedOffest; Debug.Log("Right"); } else if (Input.GetAxis("Horizontal") == 0) { transform.position = smoothedPosition; } } }

Viewing all articles
Browse latest Browse all 536

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>