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 troydhx · Oct 24, 2011 at 06:33 AM · transformpositiontouch

Moving the camera to a touch position

I am trying to move the position of the camera to the position of a touch, how do I got about changing my Touch.position into a position for the camera?

Comment
Add comment · Show 2
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 syclamoth · Oct 24, 2011 at 07:30 AM 0
Share

I don't understand your question- if you can touch a point on the screen, then the camera is already at that point? Unless you want to shoot a raycast at some collider, and then move the camera to that... Are you talking about touching a point on the ground, and focusing the camera over top of that position, like an RTS?

avatar image troydhx · Nov 08, 2011 at 01:17 AM 0
Share

I want to be able to double tap the screen and zoom to the position. I have the tap zoom working but it currently only zoom to the center of the screen.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Rod-Green · Nov 08, 2011 at 02:26 AM

There are a lot of different ways you could achieve this (including raycasting - though much slower). However one method would be to determine the touch offset from center and then move the camera based upon this offset (some scale might be necessary - depending on how you've setup your camera.

As an example:

 Touch touch = Input.GetTouch(0);
 Vector3 offset = Camera.main.ScreenToViewportPoint((Vector3)touch.position) - (Vector3.one / 2.0f);
 //3:4 screen ratio = 0.75f on Y 16:9 would be 0.5625f etc
 Vector3 scale = new Vector3(1.0f, 0.75f, 0.0f); 
 
 Camera.main.transform.Translate(offset * scale);

Now again this might take some work to get the camera to move and look at the point you want (i.e. tweaking the scale till the movement is right).

There are other ways like working out the plane the target it on and calculating the distance between the camera's current lookat on that plane and move that offset.

In any case setting up a special camera rig where the camera is a child of a gameobject that is aligned to the view plane will help you simplify any translation. As you can just move this aligned gameObject and the camera will move along this plane regardless of it's orientation.

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 Steven-Walker · Nov 08, 2011 at 02:18 AM

If you are trying to point the camera at an object and zoom, you'll need to use raycasting to first find the 3D position of the object touched. You could then use Transform.LookAt to have the camera look at the object. To make it a bit more user friendly, you'll probably want to interpolate the movement so it's smooth. I'd use iTween to do that.

Comment
Add comment · Show 4 · 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 troydhx · Nov 09, 2011 at 03:10 AM 0
Share

I am not trying to zoom to an object, I'm trying to move the camera around the xy. Think like tap zoo$$anonymous$$g a picture on a mobile device.

avatar image Steven-Walker · Nov 09, 2011 at 03:56 AM 0
Share

I could answer your question better if the problem/goal was made clearer. It's pretty ambiguous. It sounds like you might have a scene laid out like a map. If your camera is facing forward on the Z axis looking at a plane, you can center the camera by getting the touch point in 3D space then copying the X and Y transform to your camera, but leave the Z as is. Or exchange axis if the camera is looking top down.

avatar image troydhx · Nov 09, 2011 at 05:11 AM 0
Share

I have something similar to this: http://youtu.be/3HPCHtjUc1w I have the orbit, pinch and tap zoom working fine, but I am unable to get the camera to 'shift' to where the zoom is being performed.

avatar image Steven-Walker · Nov 09, 2011 at 06:49 AM 0
Share

The video helps a lot. I would do this completely different than my initial suggestion. The camera isn't really centering on any specific object, but rather the zoom is shifting the camera towards the pinch zoom center. It's more of a trick than a precise transform.

What I'd do is calculate the center by averaging the two touch points, then use a fixed interpolation (ex touchCenter.x/Screen.width) and offset the pitch and yaw of the camera. If you multiply this by the zoom change factor, you'll get more offset the more you zoom, so it will be gradual rather than an abrupt movement of the camera.

You'll also want to set limits, otherwise the user will be able to keep turning the camera further and further away from the central object.

To make this work with your existing code, you may need to insert a parent transform so you can control the regular camera orbiting separate from the centering offsets. You'll also need to play around with the calculation to dial in the amount of sensitivity you want.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make object follow touch position?Pls Help 0 Answers

Lerp not working 1 Answer

Drag+an+object+to+touch+position(Problem) 0 Answers

Move object with finger swipe 0 Answers

How to make your object follow your touch position faster or instantaneously??? 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