Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ghostpart · Aug 27, 2015 at 06:33 AM · c#cameratop down shooter

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vice_Versa · Aug 27, 2015 at 07:43 AM 0
Share

you need to be a little more specific with your question. Whats wrong with the camera? What do you want it to do?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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);
             
         }
     }
 }
 

 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges