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
1
Question by Mithosbluefish · May 30, 2013 at 10:32 PM · screenscreentoworldpointcentery0

Regarding ScreenToWorldPoint y 0

Hi,

I am writing a simple spawn mechanic for a game and need objects to be able to spawn at random points between the top of the screen and bottom of the screen.

However, when using the below code to define the bottom of the screen it returns a coordinate which is in the center of the screen rather than the very bottom (hence making my current fix dividing it by 2).

 var fieldstart = Camera.main.ScreenToWorldPoint(Vector3(0, 0, 0)).y;

To make matters even weirder the same script contains the below code, which sets the ship object to Screen.height/2, which again places it at the center of the screen (as it should do).

 Instantiate(ship,Camera.main.ScreenToWorldPoint(Vector3(170,Screen.height/2, Camera.main.nearClipPlane+25)),Quaternion(0,-180,0,0));

The code does not reset the position of the spawning objects at any point of the code, nor does any other script.

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
1
Best Answer

Answer by aldonaletto · May 30, 2013 at 10:49 PM

A screen point is in 2D space, and corresponds to an infinite line in the 3D world. In order to define a single point in the 3D world, you must pass in the Z coordinate the distance of the desired point relative to the camera - that's why Camera.main.nearClipPlane+25 is passed in the second ScreenToWorldPoint. You could try to pass the same value to the first one, like this:

 var fieldstart = Camera.main.ScreenToWorldPoint(Vector3(0, 0, Camera.main.nearClipPlane+25)).y;

This returns the Y coordinate of the point at the lower left screen corner that's at 25 units from the camera's near plane. I suspect that this isn't exactly what you want - specially since the Y coordinate alone won't make too much sense unless your camera is looking in the world +Z direction.

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 Mithosbluefish · May 30, 2013 at 10:55 PM 0
Share

Thanks, that worked :)

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

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why isn't the text centered in my game screen? 3 Answers

GUI.DrawTexture Center on screen 1 Answer

How do I keep the mouse in center of screen 2 Answers

How to Center GUI On the Screen IOS 2 Answers

Unity 3d C# GUI box goes off to the side needs to be in the center of the screen 0 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