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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by TokyoDan · Apr 10, 2013 at 09:42 AM · camerascreentoworldpointworldtoscreenpoint

How can touch input directly control an orthographic camera?

I've been messing with this for a week now and have made absolutely no progress...

I'm making a 2D board game, the game board is situated such that The Main (orthographic) Camera looks down in the Y axis to see the face of the board. So looking at the board the x axis is left/right (west/east) and the z axis is top/bottom (north/south). The y axis is not used except to initially set the height (distance) of the camera from the board and should never be changed.

The game board is like a large map in that it is bigger than the orthographic camera's size so I have to move the camera around to see the parts of the board that are outside the view of the camera.

I'm trying to swipe on my iPad's screen to move the camera across the board. A swipe to the left moves the camera to the left to show the west part of the board, and visa versa.

But I've tried many things and due to my lack of understanding of Unity's cooridnate systems and corresponding functions I can't accomplish what I want to do.

The program below makes sense to me, but itdoesn't work as a short swipe will send the camera to lever-never land. I have three questions:

  1. What am I doing wrong?

  2. Do ScreenToWorldPoint and WorldToScreenPoint work when the camera is set to orthograaphic mode?

  3. Won't ScreenToWorldPoint and WorldToScreenPoint modify the y axis too even though I don't want the y axis to be changed?

NOTE: selectedCamera* is a public variable with the Main Camera dropped into it via the Inspector.

 // Get current camera pos in world coord and convert to screen x,y.
 Vector3 ccsp = Camera.main.WorldToScreenPoint(selectedCamera.transform.position);
 
 // Get swipe delta on screen
 Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
 
 // Adjust camera's screen coord according to delta
 if(touchDeltaPosition.x < 0){
     ccsp.x -= Mathf.Abs(touchDeltaPosition.x); 
 }else if(touchDeltaPosition.x > 0){
     ccsp.x += Mathf.Abs(touchDeltaPosition.x); 
 }
 if(touchDeltaPosition.y < 0){
     ccsp.z -= Mathf.Abs(touchDeltaPosition.y); 
 }else if(touchDeltaPosition.y > 0){
     ccsp.z += Mathf.Abs(touchDeltaPosition.y); 
 }
 
 // convert camera's adjusted screen position back to world coords
 Vector3 newCcsp = Camera.main.ScreenToWorldPoint(new Vector3(ccsp.x, 0, ccsp.z));
 
 // and move camera to the new world position.
 selectedCamera.transform.Translate(newCcsp, Space.World);
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
2
Best Answer

Answer by Fattie · Apr 10, 2013 at 09:46 AM

incredibly detailed answer here

http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html

It can take a long time to master this sort of thing. yes the many coord systems are confusing. there is no quick or easy solution.

tip use Debug.DrawLine constantly to help you. when you are working basically every other line of code is Debug.DrawLine (For future ref, here's the doco for Debug.DrawLine

Comment
Add comment · Show 2 · 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 Dracorat · Apr 10, 2013 at 11:21 PM 0
Share

I want to throw in 2 cents real fast.

If I swipe, I want it to pan, which means you'd move the camera the opposite direction of the swipe (the texture under the finger would stay under the finger during the swipe).

So at the very least, maybe give an option to flip swip axis in your preferences.

avatar image Fattie · Apr 11, 2013 at 04:20 AM 0
Share

good thinking, @drac

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

12 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

Related Questions

Indicate with markers the direction of Gameobjects which are outside of the camerafield. 0 Answers

How to track a world object in a Screen Space - Camera Canvas 1 Answer

What makes Camera.ScreenToWorldPoint return different results with same input? 0 Answers

WorldToViewportPoint and WorldToScreenPoint give wrong positions when VR is enabled 1 Answer

Camera.main.ScreenToWorldPoint works within Unity editor, but not in builds 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