How to make my look at script work with a perspective camera? (2D)
I'm making a simple 2D top down game, and with an orthographic camera my below code works just fine. The problem is that I want the auto-parallax of the perspective camera, but this completely messes up the script. I was wondering if my script could be fixed to work in the way that I want, or if there was a different solution that achieves the same result. I have tried using an orthographic camera as the main camera, then tried to child a perspective camera to it, but it only looks through the ortho camera. In my script, I have an object that looks at the point question, with a sprite child to it that has it's axes locked to my plane.
Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
transform.LookAt(Camera.main.ScreenToWorldPoint(mousePos), Vector3.forward);
Very simple code, but it got the job done until I wanted parallax. I know you can move layers, but I decided against that in the case I ever wanted to experiment in multiplayer, it would get weird imo with one or all players trying to pan the layers, unless I'm overthinking it.....
If pictures or additional resources are required, I'd be happy to provide them, not sure if this is a simple problem that I can't wrap my head around due to being new or if it's a difficult one. Thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220612082652im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
When I build and run my project it seems that its lacking, plz help?! 0 Answers
Mobile Left and right move input for the player in 2D (Top Down) 0 Answers
2D Sprite in a 3D World 0 Answers
secret pathway [2D, top down] 0 Answers
How to relaise LookAt 1 Answer