- Home /
how do i make camera pan slowly?!?!?!?
I've been trying to fix it and I can't seem to make It work. I'm trying to make the camera pan slowly to one side when I click on a button. I am fairly new to coding so if one of you could help me I would much appreciate it.
here's where I'm at:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cam_S_Pan : MonoBehaviour {
public Transform CamTrans;
public Transform CamLookAt;
void Start ()
{
CamTrans = Camera.main.transform;
}
private void Update ()
{
if(CamLookAt != null)
{
CamTrans.rotation = Quaternion.Slerp(CamTrans.rotation, CamLookAt.rotation, 3 * Time.deltaTime);
}
}
public void LookAtMenu(Transform menuTransform)
{
CamLookAt = menuTransform;
}
}
this is what my menu looks like:

Why not you keep the camera fixed and move the UI object? As I see the image you give, I think you trying to make a slide UI.
Answer by lPVDl · Nov 27, 2017 at 05:21 AM
using UnityEngine;
public class Cam_S_Pan : MonoBehaviour
{
public Transform CamTrans;
public Transform CamLookAt;
void Start()
{
CamTrans = Camera.main.transform;
}
private void Update()
{
if (CamLookAt != null)
{
var targetRotation = Quaternion.LookRotation(CamLookAt.position - CamTrans.position);
CamTrans.rotation = Quaternion.Slerp(CamTrans.rotation, targetRotation, 3 * Time.deltaTime);
}
}
public void LookAtMenu(Transform menuTransform)
{
CamLookAt = menuTransform;
}
}
Your answer
Follow this Question
Related Questions
How to make the camera follow the player while still being able to be rotated? 1 Answer
URGENT Cinemachine virtual camera while falling 1 Answer
Moving camera jerks BUT this is not a camera follow script problem. Moving and strafing no issue. 1 Answer
How to make camera mouse orbit not jittery? 0 Answers
RTS Camera control - Rotation with MMB 0 Answers