Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Couldn't Solve :/] I want to setup a Cam that works like a window to the game world;

Discussion in 'Cinemachine' started by NoctisShadowzel, Aug 3, 2019.

  1. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    While thinking about story of my main project, I had an idea for a new endless hi-score making game (whatever is this genre called :p), and want to work with it as a side project. After thinking about this new idea, I noticed I don't know how to implement camera system I want (again) for this project. I draw a simple Pixel-Art (not Paint this time :)), that sums up what I want from Camera; HowCameraShouldWork-ForSharing.gif
    What I want is; when I move my Camera, I want it show only some part of screen relative to the Camera position/rotation. I want it to look like game world is not moving with Camera, Camera isn't a part of game; instead a window that opens to the game.

    Main game mechanics will be based on accelerometer data, and I will work on a 2D environment.
    I could just change Transform of game but this requires more work than saying it easily.

    1. Can you help me to achieve this Cam system? Also if I can't achieve this with Cinemachine, can you redirect this thread to Scripting forums?
    2. I seen a few games which uses something similiar to this, but I don't know names of any. If you know any game (2D preferred) can you give me references from them? Idea is still hot, some references will be useful for inspiration.

    Thank you for taking time ^.^ !
     
  2. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    EDIT: Last try, didn't solved the problem.

    After thinking a little more, I noticed the solution is; changing rotation of game objects that needs to be affected by the rotation/Dutch of Camera to the negative of VCam's Dutch will give me the result I want.

    But right now, I can't get VCam's Dutch value! I setup a reference to it from a test script, Dutch value always shows zero. I also attached a script to store Dutch value on VCam, Debug.Log always logs zero. I'm not sure what is wrong...

    Code (CSharp):
    1. public class VCamDutch : MonoBehaviour
    2. {
    3.     public float DutchAsQuaternion { get; set; } = 0f;
    4.     public float DutchAsEulerAngles { get; set; } = 0f;
    5.  
    6.     LensSettings vCamLens = new LensSettings();
    7.  
    8.     void Start()
    9.     {
    10.         vCamLens = this.gameObject.GetComponent<CinemachineVirtualCamera>().m_Lens;
    11.         DutchAsQuaternion = vCamLens.Dutch;
    12.         DutchAsEulerAngles = DutchAsQuaternion * Mathf.Rad2Deg;
    13.     }
    14.  
    15.     void Update()
    16.     {
    17.         Debug.Log("VCamDutch is: " + vCamLens.Dutch);
    18.         DutchAsQuaternion = vCamLens.Dutch;
    19.         DutchAsEulerAngles = DutchAsQuaternion * Mathf.Rad2Deg;
    20.     }
    21. }
    This is the script that stores Dutch value. I'm confused... Also, I think what I want isn't clear. So, no one responded...
     
    Last edited: Aug 4, 2019
  3. NoctisShadowzel

    NoctisShadowzel

    Joined:
    Dec 27, 2018
    Posts:
    57
    Think it like that, at my first post there is a gif; pretty much explaining what I want, when I tilt my device left, I want my VCam to tilt in that side too, this can be achieved via accelerometer input. And I want to, Camera's edges to cut trough game world like a physical window, only show what lefts between screen limits; by rotating it in counter-direction of Camera. It must almost look like game world didn't rotated and you are looking through a rectangle and seeing only what is in the rectangles limits, like in real world.

    If you still didn't understand me, problem maybe my English. I learned it myself...