Search Unity

3rd person camera looks from one side!

Discussion in 'Physics' started by edy_sefu41, Mar 20, 2018.

  1. edy_sefu41

    edy_sefu41

    Joined:
    Mar 14, 2018
    Posts:
    14
    PLEASE HELP

    So I am building one of my first major projects and after setting up the camera, i can see that it is moving from the side. I want the camera to see from behind the player. Also, I can't turn it around, I added a script to turn it by pressing A and D but they seem very buggy.

    Video: http://recordit.co/BCR4ajzXNK (when the screen is shaking I'm trying to turn the screen by pressing A and D)


    Camera inspector: https://imgur.com/a/o3dKo


    Camera Controller Scipt:

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

    public class CameraController : MonoBehaviour {

    public Transform target;

    public Vector3 offset;
    public float zoomSpeed = 4f;
    public float minZoom = 5f;
    public float maxZoom = 15f;

    public float pitch = 2f;

    public float yawSpeed = 100f;

    private float currentZoom = 10f;
    private float currentYaw = 0f;


    void Update()
    {
    currentZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
    currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom);

    currentYaw = Input.GetAxis("Horizontal") * yawSpeed * Time.deltaTime;
    }



    void LateUpdate ()
    {
    transform.position = target.position - offset * currentZoom;
    transform.LookAt(target.position + Vector3.up * pitch);

    transform.RotateAround(target.position, Vector3.up, currentYaw);
    }
    }
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    try this line for rotate:
    currentYaw += Input.GetAxis("Horizontal") * yawSpeed * Time.deltaTime;

    If you will have the camera all the time behind the player, then you can just make it child from the player (without camera script) or set an anchor point somewhere behind player and move camera at this point..
     
    Last edited: Mar 20, 2018