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 /
avatar image
0
Question by Ameletiadis · Apr 19, 2018 at 10:38 AM · cameramultiplayerboundslocalfieldofview

Local Multiplayer Camera

Hello everyone i am a newbie in Unity and i am trying to make a simple local multiplayer game, i am facing right now a problem with my perspective camera.I followed a tutorial on youtube and i want to apply that script in my game's scenario.alt text

This is the angle i want to have on my game.The problem is that i use bounds to keep every target within bounds but in this scenario i am confused and not exactly sure if i want to use bounds to keep all targets withing my camera's view.The problem is that players do get out of camera bounds and that make's it unplayable to say the least!Here's the script for the camera

[RequireComponent(typeof(Camera))] public class MultipleCamera_S : MonoBehaviour {

 // Use this for initialization
 public Transform[] m_Targets;

 public Vector3 m_Offset;

 private Vector3 m_Velocity;

 public float m_SmoothTime = .5f;

 public float m_MinZoom = 40f;
 public float m_MaxZoom = 10f;
 public float m_ZoomLimiter = 50f;
 private Camera m_Camera;
 public GameObject m_Level;
 void Start ()
 {
     m_Camera = GetComponent<Camera>();
 }
 
 // Update is called once per frame
 void Update ()
 {    

 }

 void CheckIfTargersAreinBounds()
 {
     for (int i = 0; i < m_Targets.Length; i++)
     {
         if (m_Targets[i].position.x > m_Level.transform.lossyScale.x && m_Targets[i].position.x < m_Level.transform.lossyScale.x)
         {
             m_Targets[i] = null;
         }

         if (m_Targets[i].position.z > m_Level.transform.lossyScale.x && m_Targets[i].position.z < m_Level.transform.lossyScale.z)
         {
             m_Targets[i] = null;
         }
     }
 }



 void LateUpdate()
 {
     if (m_Targets.Length == 0)
         return;
     Move();
     Zoom();
     CheckIfTargersAreinBounds();
 }

 void Move()
 {
     Vector3 centerPoint = GetCenterPoint();

     Vector3 newPosition = centerPoint + m_Offset;

     transform.position = Vector3.SmoothDamp(transform.position, newPosition, ref m_Velocity, m_SmoothTime);
 }

 void Zoom()
 {
     float newZoom = Mathf.Lerp(m_MaxZoom, m_MinZoom, GetGreatestDistance()/ m_ZoomLimiter);

     m_Camera.fieldOfView = Mathf.Lerp(m_Camera.fieldOfView,newZoom,Time.deltaTime);

 }


 float GetGreatestDistance()
 {
     var bounds = new Bounds(m_Targets[0].position, Vector3.zero);
     for (int i = 0; i < m_Targets.Length; i++)
     {
         bounds.Encapsulate(m_Targets[i].position);
     }
   
     return bounds.size.x;
 }



 Vector3 GetCenterPoint()
 {
     if (m_Targets.Length == 1)
     {
         return m_Targets[0].position;
     }

     var bounds = new Bounds(m_Targets[0].position,Vector3.zero);
     //camera fix

     for (int i = 0; i < m_Targets.Length; i++)
     {
         bounds.Encapsulate(m_Targets[i].position);
     }
     return bounds.center;
 }

}

I understand i am adding only the x component of the bounds which doesnt make sense but adding the z as well wont help in this case!Any ideas or help would be welcome!Thanks in advance!

screenshot.jpg (44.8 kB)
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

175 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make the camera follow 4 players at all times, zooming in and out, along with some extra screen space padding on all 4 sides, so that they arent always sitting on the edge ? 1 Answer

New Input Manager Split Screen and Cinemachine 0 Answers

Local Mulitplayer 2d Camera 0 Answers

TopDown local multiplayer camera edges collision? 1 Answer

Mathf.SmoothDamp happens instantly 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