Top Down Camera View Problem
Hello, i work on a 3d top down game, and recently i try to improve my camera system by adding and extended view like Running With Rifles's one ( something like this: http://runningwithrifles.gamepedia.com/Line_of_Sight,_Vision). And i achieved something but not very good, it doesn't work how it should do. So, if somebody can help me with an advice or an example, i will appreciate very much.This is the code:`
 public class CameraManager : MonoBehaviour
 {
     public Transform target;
     public GameObject player;
     public float distance = 2.0f;
     public float centerOffset = 1.0f;
     public float height = 15.0f;
     public float damping = 3.0f;
     private float inputX;
     private float inputY;
     private float wantedHeight;
         
     void Update() {
         if(target) {
             wantedHeight = player.transform.position.y + height;
             
             inputX = (Input.mousePosition.x - Screen.width * 0.5f) / Screen.width;
             inputY = (Input.mousePosition.y - Screen.height * 0.5f) / Screen.height;
             
             Vector3 targetPos = new Vector3(target.position.x + inputX, wantedHeight, target.position.z + inputY - distance) + player.transform.forward * centerOffset;
             transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * damping);
             transform.eulerAngles = new Vector3(90 - inputY, 0, 0);
         }
     }
 }`
 
               Thank you.
you need to be a little more specific with your question. Whats wrong with the camera? What do you want it to do?
Answer by tonmoyRoy · Nov 13, 2016 at 10:24 PM
Okay I have seen your code, Me also researching about the camera control system of the game, "Running With Rifles". I searched a lot but didn't find any good references of that type of moment system. After that I saw your Question and I just used it and after some modification, I finally found something 98% closer to that game, ummm its not perfect, but its closer enough. Hope that will be helpful to you, here is my modification on your code:
 using UnityEngine;
 using System.Collections;
 
 public class CameraManager : MonoBehaviour {
 
     public Transform target;
     public GameObject player;
     public float distance = 1f;
     public float centerOffset = 0.1f;
     public float height = 18f;
     public float damping = 10f;
     private float inputX;
     private float inputY;
     private float wantedHeight;
 
     void Update() {
         if(target) {
             wantedHeight = player.transform.position.y + height;
 
             inputX = (Input.mousePosition.x - Screen.width * 0.5f) / (Screen.width/8);
             inputY = (Input.mousePosition.y - Screen.height * 0.0001f) / (Screen.height/8);
 
             Vector3 targetPos;
             if (Input.mousePosition.y > 5) {
                 targetPos = new Vector3 (target.position.x + inputX, wantedHeight, target.position.z + inputY - distance) + player.transform.forward * centerOffset;
             } else {
                 targetPos = new Vector3 (target.position.x + inputX, wantedHeight, target.position.z + inputY - distance) + player.transform.forward * centerOffset;
             }
             transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * damping);
             //transform.eulerAngles = new Vector3(90 - (inputY*2f), 0, 0);
             
         }
     }
 }
 
 
 
              Your answer
 
             Follow this Question
Related Questions
Rotate camera and player with mouse 2d top-down shooter in C# 1 Answer
c# - error CS0103: The name `hit' does not exist in the current context (cardboard switching) 1 Answer
Clamping when Zoom changes? 0 Answers
code error CS0119 field of view script 1 Answer
How to access camera Dont Clear in camera clear flags using c# 1 Answer