- Home /
Top Down Shooter: Panning Towards Cursor and / or rotating camera
Hi guys,
What im trying to achieve is a top down shooter camera which allows the camera to pan towards the cursor while keeping the player on screen. At the moment, when the player begins walking towards the camera, its hard for them to see potential enemies etc. as the camera is at a slight angle. (as illustrated below)
I think effectively, what im trying to make the camera script do, is calculate the middle position between the cursor and the player on screen and pan the camera towards that allowing the player to not feel like they cant see where theyre aiming.
Or to make the cursor the target of the camera but limit the cursor to the edges of the screen so that the camera doesnt pan so far that you can no longer see the player?
My current camera script at the moment which simply follows the player is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour {
public Transform cameraTarget;
public float cameraSmoothing = 5f;
Vector3 offset;
// Use this for initialization
void Start ()
{
offset = transform.position - cameraTarget.position;
}
// Update is called once per frame
void FixedUpdate ()
{
Vector3 targetCameraPosition = cameraTarget.position + offset;
transform.position = Vector3.Lerp(transform.position, targetCameraPosition, cameraSmoothing * Time.deltaTime);
}
}
Would really appreciate any advice / help or alternative camera ideas! Cheers guys.
Reference of Camera Style: AlienSwarm : https://www.youtube.com/watch?v=8ob7Y6spUW8&t=252s
Your answer
Follow this Question
Related Questions
Vector3.SmoothDamp() - smoothTime unit 0 Answers
Pan RTS camera controller without changing elevation/zoom 0 Answers
Locking cursor, while moving camera. 0 Answers
lock camera to when open popup screen 3 Answers