Hello guys! I am pretty new to unity and game programming in general so the error may be really easy and evident, but i just cant help myself and find it
The code is supposed to smoothly move the camera, and it kind of does that, but it has a strange glitch that happends randomlly and pretty often, it doesnt feel 100% consistent, it feels like its not synced with the frames of the game in some way. Also, it creates some strange effects near scenary borders, like some kind of blur.
Heres the code:
using UnityEngine;
using System.Collections;
public class Camara : MonoBehaviour {
public GameObject objetoaseguir;
public float velocidad_aumento_x,velocidad_aumento_y;
private float eje_y,eje_x;
// Use this for initialization
void Start () {
eje_x = objetoaseguir.transform.position.x;
eje_y = objetoaseguir.transform.position.y;
}
// Update is called once per frame
void Update () {
movimientocamara ();
}
void movimientocamara()
{
// Variables
float origen_x, objetivo_x,origen_y,objetivo_y;
//Asignacion
origen_x = gameObject.transform.position.x;
origen_y = gameObject.transform.position.y;
objetivo_x = objetoaseguir.transform.position.x;
objetivo_y = objetoaseguir.transform.position.y;
//Funcion
if (origen_x != objetivo_x)
{
eje_x = Mathf.Lerp (origen_x, objetivo_x, velocidad_aumento_x * Time.deltaTime);
}
if (origen_y != objetivo_y)
{
eje_y = Mathf.Lerp (origen_y, objetivo_y, velocidad_aumento_y * Time.deltaTime);
}
else
{
eje_x = objetoaseguir.transform.position.x;
eje_y = objetoaseguir.transform.position.y;
}
transform.position = new Vector3 (eje_x, eje_y, gameObject.transform.position.z );
}
}
And heres a link to the camera working so you can see what i mean: https://dl.dropboxusercontent.com/u/42147973/Juegos/Scroller/Scroller.html
Thanks for your time