Question by
KyleRansford · Aug 06, 2017 at 08:37 PM ·
c#controllertransitioncamera movementfollow player
Mega Man Style Camera Movement
How can I get the camera to follow the player like in the NES Mega Man games? My current camera only follows the player left to right and not up or down, but I want it to "pause" like it does in the Mega Man games when you go to a different area. Here is my current camera script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour {
public GameObject target;
public float followAhead;
private Vector3 targetPosition;
public float smoothing;
public bool followTarget;
// Use this for initialization
void Start () {
followTarget = true;
}
// Update is called once per frame
void Update () {
if(followTarget)
{
targetPosition = new Vector3(target.transform.position.x, transform.position.y, transform.position.z);
if (target.transform.localScale.x > 0f)
{
targetPosition = new Vector3(targetPosition.x + followAhead, targetPosition.y, targetPosition.z);
}
else
{
targetPosition = new Vector3(targetPosition.x - followAhead, targetPosition.y, targetPosition.z);
}
//transform.position = targetPosition;
transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing * Time.deltaTime);
}
}
}
Comment