- Home /
Question by
zerikscythe · Sep 29, 2013 at 09:18 AM ·
animationcamerasprite
Camera movement causeing jittery sprites.
I'm working on a script that will move and offset my camera, based on my characters position. he is a 2d character being animated on a sprite sheet, when the camera is NOT moving he plays fine but something in my code is creating what appears to be a single frame stutter, until you move to the far end of the screen where the tracking stops and he renders fine again.
using UnityEngine;
using System.Collections;
public class test_cam : MonoBehaviour {
float offset;
float offset_maxL;
float offset_maxR;
private PlayerController p;
void Start () {
p = GameObject.Find("Player").GetComponent<PlayerController>();
}
void Update ()
{
offset_maxR = p.transform.position.x + 99;
offset_maxL = p.transform.position.x - 99;
if (p.goingRight == true) //going right
{
offset += 7f;
if (offset > offset_maxR)
{ offset = offset_maxR; }
}
else if (p.goingRight == false)//going left
{
offset -= 7f;
if (offset < offset_maxL)
{ offset = offset_maxL; }
}
else //still
{ }
GameObject.Find("Main Camera").transform.position = new Vector3(offset, -1.71f, -131.19f);
}
}
Comment
Your answer