Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Matching a position of an object so it would display the same on a different camera.

Discussion in 'Scripting' started by pixelfixation, Jun 21, 2016.

  1. pixelfixation

    pixelfixation

    Joined:
    Feb 7, 2014
    Posts:
    29
    OK so I have two cameras in my game and I have run into a situation where I need to move an object from the view of one camera to the other without the playing knowing that happened. So I need to find a way to match the position of an object so it appears the same on the second camera as it did on the first.

    Any ideas? Thanks
     
  2. listener

    listener

    Joined:
    Apr 2, 2012
    Posts:
    179
    One way would be like this:

    http://docs.unity3d.com/ScriptReference/Camera.html

    You can basically use WorldToScreenPoint to find where the object is in the screenspace then convert using other camera ScreenToWorldPoint to get world space point of second cameras screen space.
     
    ericbegue likes this.
  3. pixelfixation

    pixelfixation

    Joined:
    Feb 7, 2014
    Posts:
    29
    I was hoping there would be some vector math magic that could do this. I tried this method and its close but definitely not exact. Thanks though.
     
  4. listener

    listener

    Joined:
    Apr 2, 2012
    Posts:
    179
    If there are differences in two cameras like view frustum there can be differences if one of your cameras is very wide and other is very narrow you of course can get object appearing on first one in corner centered in second one.