- Home /
No help, waste of my time. Will figure it out myself.
Main Camera XYPoint To Background Camera XYPoint
Hey i'm just wondering how i'd tackle the problem of getting x , y values from a point in the main camera view, to it's corresponding point in another camera view, which is used for the background.
These cameras are both orthographic and are of different sizes in that projection. Additionally both camera transform positions are different.
Has anybody here reading this already solved this? Would appreciate a little help
Answer by MaxGuernseyIII · Nov 04, 2017 at 05:13 AM
I guess I would probably use something like ScreenPointToRay or ViewportPointToRay. You should then be able to do a ray cast and get a world point where the screen point hits an object. From that, you could use WorldToScreenPoint or WorldToViewportPoint on the other camera.
It seems like you want the screen version rather than the viewport version but I don't know enough about what you are trying to accomplish to really help you with that choice.
Hey $$anonymous$$ax, thank you for that. Stoked somebody got back to me. Here's a screenshots to better understand what i'm trying to do.
Hope that helps paint a better picture. If there's nothing else to add, i'll try your approach. Thanks again
Additionally before I read this, i coded the following for the background crosshair. $$anonymous$$eep in $$anonymous$$d i didn't fully understand the problemm so yes this doesn't work lol
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BkgdCrosshair : $$anonymous$$onoBehaviour
{
[Header("$$anonymous$$AIN AI$$anonymous$$ REF")]
[Tooltip("Place the main cam crosshair here, to follow main cam crosshair")]
public Transform _mainAimTr;
[Header("$$anonymous$$AIN CA$$anonymous$$ERA REF")]
[Tooltip("Place the bkgd cam here")]
public Camera _mainCam;
private Vector3 _viewPos;
private Transform _myTransform;
//https://answers.unity.com/questions/1429502/main-camera-xypoint-to-background-camera-xypoint.html?childToView=1429503#answer-1429503
void Start()
{
_mainCam = GetComponent<Camera>();
if(_mainCam == null)
{
_mainCam = Camera.main;
}
_viewPos = _mainCam.WorldToViewportPoint(_mainAimTr.position);
_myTransform = this.transform;
}
void Update()
{
_viewPos = _mainCam.WorldToViewportPoint(_mainAimTr.position);
_myTransform.position = _viewPos;
}
}
Did the way of addressing this that I suggested in my answer not work? You added a bunch more detail but you didn't say whether what I suggested worked or not...
Follow this Question
Related Questions
i need help about players hands positions in 2D multiplayer card game 0 Answers
ScreenToWorldPoint not working 1 Answer
Camera.main.ScreenToWorldPoint not outputting expected results. 1 Answer
Direct positioning with a perspective camera? 2 Answers
How can you access the Game screen and its properties from an Editor Script? 1 Answer