Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Feedback Rotate camera

Discussion in 'Audio & Video' started by isc20703, May 29, 2019.

  1. isc20703

    isc20703

    Joined:
    Apr 3, 2019
    Posts:
    9
    How do i rotate the camera around a fixed object. Can i do it using vector variables? here is the code i am currently using:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class camera : MonoBehaviour
    {

    public Transform player; // A variable that stores a reference to our Player
    public Vector3 back;// A variable that allows us to offset the position (x, y, z)
    public Vector3 left;
    public Vector3 right;
    public Vector3 front;

    void Update()
    {
    if (Input.GetKey("w"))
    {
    transform.position = player.position + back;
    }

    if (Input.GetKey("a"))
    {
    transform.position = player.position + left;
    }

    if (Input.GetKey("s"))
    {
    transform.position = player.position + front;
    }

    if (Input.GetKey("d"))
    {
    transform.position = player.position + right;
    }
    }
    }
     
unityunity