Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 a7BiT-psycho · Jun 14, 2014 at 07:37 PM · orthographicorthographic cameraplay modeedit mode

ScreenToWorldPoint on orthographic cameras has different results in play and edit mode

Hello Unity Answers, My work progress is currently hindered hindered by the fact that the ScreenToWorldPoint method has different results in play and edit mode when used with an orthographic camera.

My Test behaviour: (The MethodButtonAttribute allows me to invoke a method from the inspector)

 using SevenBiT.Inspector.Attributes;
 using UnityEditor;
 using UnityEngine;
 using System.Collections;
 
 [MethodButton("TestPoints", "TestPoints")]
 public class PointTestBehaviour : MonoBehaviour
 {
     public Camera PerspCam;
     public Camera OrthoCam;
 
     public void TestPoints()
     {
         float width = Screen.width;
         float height = Screen.height;
 
         Debug.Log(
             "Persp: " + PerspCam.ScreenToWorldPoint(new Vector3(0, 0)) +          
             "\nOrtho: " + OrthoCam.ScreenToWorldPoint(new Vector3(0, 0)));
 
         Debug.Log(
             "Persp: " + PerspCam.ScreenToWorldPoint(new Vector3(width, 0)) +
             "\nOrtho: " + OrthoCam.ScreenToWorldPoint(new Vector3(width, 0)));
 
         Debug.Log(
             "Persp: " + PerspCam.ScreenToWorldPoint(new Vector3(width, height)) +
             "\nOrtho: " + OrthoCam.ScreenToWorldPoint(new Vector3(width, height)));
 
         Debug.Log(
             "Persp: " + PerspCam.ScreenToWorldPoint(new Vector3(0, height)) +
             "\nOrtho: " + OrthoCam.ScreenToWorldPoint(new Vector3(0, height)));
     }
 }

This has the following results: (Top: Edit mode, Bottom: Play mode) http://prntscr.com/3sspan

In case a video can demonstrate the problem better: https://www.youtube.com/watch?v=J40oOd-mjC8

I would assume that this is related to the different mathematical formulas required to calculate the world points which haven't been implemented in the edit mode (or the play mode?). Or it could be me missing important information, or there is a known workaround for orthographic cameras which I haven't been able to find.

Best regards, psycho

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wisteso · Jun 14, 2014 at 09:12 PM

I don't think you can rely on consistent results between Play and Edit mode when using ScreenToWorldPoint. I think this is because the camera dimensions depend upon the viewport dimensions, and those dimensions change between Play and Edit mode. This is because the camera dimensions are normalized. If you want non-normalized dimensions, I think you need to use the "pixelRect" property via code (it's not exposed in the inspector).

You can probably test the Play/Edit resolution difference by printing the results of Screen.width/height in Edit mode and in Play mode.

Comment
Add comment · Show 1 · Share
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
avatar image a7BiT-psycho · Jun 15, 2014 at 08:49 PM 0
Share

Thank you. This already helped out a lot. But now I'm facing another problem: A transform should have a specific offset from the top left corner of my camera. The problem is that it that the offset gets completely screwed up if the game view gets resized on the y-axis.

 public Camera OrthoCam;
 public Transform TestTrans;
 public Vector2 Offset;
 
 private void Update()
 {
     Rect r = OrthoCam.pixelRect;
     //float width = r.width;
     float height = r.height;
 
     TestTrans.position = OrthoCam.ScreenToWorldPoint(new Vector3(0 + Offset.x, height + Offset.y, 10));
 }

Again, in case some visualization is required: https://www.youtube.com/watch?v=46a3jVm4boI

Its probably related to the the aspect ratio of the camera changing. But the weird thing is that everything says fine if the game view gets resized on the x-axis.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to use ScreenPointToRay for orthographic cameras 1 Answer

Orthographic camera size for 1080p quad @ 1920mx1080m 1 Answer

Best Setting Size Orthographic Camera? 1 Answer

How to make WorldToScreenPoint work with an orthographic camera? 1 Answer

orthographic camera with deferred lighting 2 Answers


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