- Home /
iTween acting strangely when being used to move camera
I'm trying to use iTween to move my camera in a top down 2D game when the player object reaches close to the edge of camera view. I'm using the following script to check when the player collider enters any of four other box colliders which are positioned near the edges of camera view (and children to the main camera). In practice the camera moves exactly as I want when the player reaches the edge but after the camera stops moving it suddenly teleports somewhere out of view leaving blankness on the screen.Does anyone know what could be causing this?
public var cameraView : GameObject;
var XNum:float;
var YNum:float;
function Start() {
cameraView = GameObject.Find("Main Camera");
}
function OnTriggerEnter2D(other : Collider2D) {
if(other.CompareTag("Player")) {
iTween.MoveTo(cameraView, new Vector2(cameraView.transform.position.x + XNum, cameraView.transform.position.y + YNum), 2);
}
}
EDIT: I realised that iTween was changing the z-axis even though I'm using a vector2, so changing it to a vector3 and setting the z position where I wanted it fixed the problem. I'm not sure if I should delete this or if it could be useful to others in the future?
you should post that comment as an answer, then press the check next to it so that the site knows that the question is answered