Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 vaggLivaditis · Aug 21, 2011 at 11:53 AM · touchscreentoworldpoint

Novice problem on Android with Touch position and object world placement. Help!

Hi, I am just trying to spawn a little cube in my scene where I touch the screen. But the behavior i get is the following:

alt text

As you can see it seems that whatever i get from ScreenToWorldPoint is centered around some sort of center (maybe the camera?) and also the input seems to be tiny (thats why i multiply the 2 touch inputs by 30 (i.e. touch.position.x*30) to be able to see the different cubes drawn on radically different places as I press different screen points (before the multiplication all of the cubes where drawn at the same spot more or less)

Seems like I am doing something wrong coordinate system wise, but i dont get what. Any help will be greatly appreciated, thanks!!!

 function DebugCheckInput () {
         while(true){
             if(Input.touchCount >=1) {
                 touch = Input.GetTouch(0);
                 if (touch.phase == TouchPhase.Began) {                    
                     //Camera.main.nearClipPlane
                     touchPos3D = Camera.main.ScreenToWorldPoint(Vector3(touch.position.x*30, touch.position.y*30, Camera.main.nearClipPlane));
                     Manager.use.SpawnDebugBlock (touchPos3D.x, touchPos3D.y);                    
                 }
                 else if (touch.phase == TouchPhase.Moved){
 
                 }
                 else if (touch.phase == TouchPhase.Ended)
                 {
                 }
             }
             yield;
             }
 }
 
 function SpawnDebugBlock (xPosIn : float, yPosIn : float) {
     // just to see where i am touching, if
     var debug_cubes = gameObject.FindGameObjectsWithTag("Cube");
     Instantiate (debug_cubes[0], Vector3(xPosIn, yPosIn, 0.0), Quaternion.identity);
 }


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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by vaggLivaditis · Aug 21, 2011 at 11:55 AM

Hmm I seem to have a problem with the image, the url is: http://www.freeimagehosting.net/102af

Comment
Add comment · 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
0

Answer by vaggLivaditis · Aug 21, 2011 at 01:48 PM

Damn I just found what was happening, seems that the problem was the Camera.main.nearClipPlane, as soon as i put 16.0 (my cameras distance to where i want the cube to spawn) all is ok. Strange function though, I would expect that the screen space is where the camera is

Comment
Add comment · 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
0

Answer by crazypit · Dec 07, 2011 at 06:40 PM

Hello,

I have the same problem but it does not seem to go away with correct z setting. I also get some coordinates that are centered around my current camera position. Nevertheless, these coordinates have nothing to do with correct World coordinates. Did you find a solution to this?

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

iPad touch is offset! Unity2d. 2 Answers

Instantiate Prefab 1 Answer

Touch.ScreenPosition doesnt work ? 0 Answers

Problem with ScreenToWorldPoint and touches (C#) 2 Answers

GUITexture touch switch between two cameras 1 Answer


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