- Home /
2d orthographic camera follow
Greetings all, i know this is a pretty common question but i cant seem to find a tutorial or answer that is specifically helpful
what ive got is a 2d top down game using an orthographic camera. id like the camera to follow the player with maybe a bit of a delay, and the ability to scroll in and out with the scroll wheel.
im not sure how that delay function works, and im pretty sure the scrolling in and out is just a button detection on the scrollwheel thatll change the "size" value in the orthographic camera.
ive tried making the camera a child of the player, but when the player rotates the camera rotates and its really disorienting.
even if some one could just point me to a tutorial to scrolling/delayed following/any kind of following that would be extremely helpful
thank you, peace out.
Answer by robertbu · Sep 28, 2013 at 04:31 AM
Here is a starter script:
#pragma strict
var player : Transform;
var trackingSpeed = 2.0;
var zoomSpeed = 5.0;
function Start () {
if (player == null)
player = GameObject.Find("Player").transform;
}
function Update () {
var pos = player.position;
pos.y = transform.position.y;
transform.position = Vector3.Lerp(transform.position, pos, trackingSpeed * Time.deltaTime);
camera.orthographicSize += Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
}