Question by
jhunglow · Jul 26, 2016 at 08:33 PM ·
camera followcamera script
Camera stutter when following player
I am making a 2.5D game and when the player(a rolling ball) moves side to side, it stutters as if the camera is lagging behind.
Comment
here is my code:
using UnityEngine; using System.Collections;
public class FollowCamera : $$anonymous$$onoBehaviour { public GameObject target = null; public bool orbitY = false;
private Vector3 positionOffset = Vector3.zero;
// Use this for initialization
void Start () {
positionOffset = transform.position -= target.transform.position;
}
// Update is called once per frame
void LateUpdate () {
if(target != null)
{
transform.LookAt(target.transform);
if(orbitY)
{
transform.RotateAround(target.transform.position, Vector3.up, Time.deltaTime * 15);
transform.position = target.transform.position + positionOffset;
}
}
}
}
Best Answer
Answer by Jessespike · Jul 26, 2016 at 09:43 PM
void Start () {
positionOffset = transform.position - target.transform.position;
}
float elapsed = 0f;
// Update is called once per frame
void LateUpdate () {
if(target != null)
{
transform.position = target.transform.position + positionOffset;
if(orbitY)
{
transform.RotateAround(target.transform.position, Vector3.up, elapsed += Time.deltaTime * 15f);
}
transform.LookAt(target.transform);
}
}
Your answer
Follow this Question
Related Questions
Where do you find camera target on tank game? 0 Answers
Camera Collision Problem 0 Answers
3rd person camera for Roll a Ball 1 Answer
how to make camera follow instantiated object? 0 Answers
smooth follow camera too slow when dash 0 Answers