- Home /
question about camera limits to the screen
i make 2d game with the main cam. i want to do this thing. i have player that he can go only forward when he try go back he can go only to the tips of the sceern. i did this script:
public float PlayerSpeed; protected bool PlayerBlockedMovment = false; // Use this for initialization void Start () { //transform.position = new Vector3(-5, 2, transform.position.z);
}
// Update is called once per frame void Update () { float amountToMove = PlayerSpeed Input.GetAxisRaw("Horizontal") Time.deltaTime; Vector3 toMovePlayer = Vector3.right * amountToMove; //Debug.Log(transform.position);
Debug.Log(transform.position.x <= -19.0f);
if (transform.position.x >= -19.0f &&! PlayerBlockedMovment)
{
Debug.Log("Entered");
PlayerBlockedMovment = true;
}
else
{
PlayerBlockedMovment = false;
transform.Translate(toMovePlayer);
if (transform.position.x >= 10.7f) {
MoveCameraWithPlayer(toMovePlayer);
}
}
}
private void MoveCameraWithPlayer(Vector3 toMovePlayer) { Camera.main.transform.Translate(toMovePlayer); }
now its give few issues: 1. when i go back he ignore and go back even after the i finish my screen 2. when go forward at first my cam and my player going well but then i try to go back its odd the player just stay in same point this the position.x come to that value then all i thing OK. now my question can i have a math calc here to fix this issue?