Hi, this is a 2d side platformer game.
when player triggered into a box collider, then i like to move player and camera to new position.
i like to move the camera with a speed.
here is my code, which is not working well. can someone help me please with camera movement?
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("ExitDoor"))
{
// this is player new position
transform.position = new Vector3(4.8f, 6.5f,0);
// in order to move the camera
StartCoroutine(MoveCamera());
}
}
// camera movement with a speed
private IEnumerator MoveCamera(Vector3 startPos, Vector3 endPos, float speed)
{
}
For camera motion these days I’m told all the cool kids are using Cinemachine, a package you can install from Unity3D that does all kinds of camera goodness.
1 Like
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("ExitDoor"))
{
// this is player new position
transform.position = playerNewPosition[0].position;
//in order to move the camera
StartCoroutine(MoveCamera());
}
}
// camera movement with a speed
private IEnumerator MoveCamera()
{
yield return new WaitForSeconds(2f);
Camera.main.transform.position = Vector3.Lerp(transform.position, cameraNewPosition, cameraMoveSpeed);
}
i dont use that in this game, can you help me with above code?
the problem is that camera does not slide and moves but it moves instantly in wrong position,
thanks for help also.
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position,
cameraNewPosition, cameraMoveSpeed * Time.deltaTime);
this also does not work.