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 Lencias · Apr 15, 2012 at 12:54 PM · touchlookattouchscreenworldspacescreenspace

Zoom in on tapped point in 3D space

Hey everyone -

I'm working on a project for class that's a shooting gallery style game for mobile. It takes place in a 3D environment, and I'm trying to implement a mechanic where the camera to zooms into the point where you tapped on the touchscreen... I know I have to use touch.position and lookAt, and I know how to zoom, but I'm not sure how to make it all work; my main problem is that touch.position only returns a Vector2, and I need a Vector3 (x, y, and z for the position/target I'm aiming at) for lookAt. Just tossing in a zero for z doesn't work then it zooms in on a completely different position than what I need.

Help? Thanks! =]

Comment
Add comment · Show 1
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 BigBlob · Apr 15, 2012 at 06:26 PM 0
Share

I think you need to specify exactly which vector, example : Vector3.up Vector3.down Vector3.left

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Lttldude · Apr 15, 2012 at 06:47 PM

What you need to do is use a RayCast. This ideally will send a ray from your screen point where you touch to a 3D point. The ray has to hit a collider or rigidbody, so be sure you have those setup. They can be invisible. When the ray does hit a collider, you can use RayCastHit.point to get the 3D point, and that is where you can move your camera to.

 var ray = Camera.main.ScreenPointToRay (Vector3(Touch.position.x, Touch.position.y, 0)); //construct the ray
 var hitInfo : RaycastHit; //stores the information of the ray when it hits something
 var distance = 100; //how far ray will go, it needs to be able to go from the camera to the colliders
 if (Physics.Raycast (ray, hitInfo, distance)) {
     if(hitInfo.collider.tag == "invisibleWall") //this is optional, and can be used if you want the camera to move only when the ray hits a certain type of collider
     Camera.main.transform.position = hitInfo.point; //move camera to the point the ray hit something
 }

Tell me if this doesn't work or you need more help.

Good Luck.

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

6 People are following this question.

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

Related Questions

World and Screen space Multiplayer[Touch Screens] 1 Answer

Input.mousePosition equivalent to first finger touch? 3 Answers

Scale Gameobject with defined size in pixels 2 Answers

World space and UI space 3 Answers

Touch on 3D model and Fade-out 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