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 KamiKaze425 · Apr 03, 2013 at 12:43 AM · touchangledrag

Touch drag gameObject with any camera angle

I know there are many posts/questions on touch drag, but everything I found normally involved a camera angle that was a multiple of 90 degrees. I have a game for mobile devices that has a 60 degree camera angle, and we want users to be able to drag objects. The only issue is that dragging up and down on the screen affects both the Y and Z position of the gameObject to where its slightly off the finger, but follows it for the most part. I also don't want to move the Y position of the gameObject

my basic function is:

 while(touched)
 {
    thisTransform.position = mainCamera.ScreenToWorldPoint(Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, (thisTransform.position-mainCamera.transform.position).magnitude));
    thisTransform.position.y = 0;
 }

I've also tried using an offset version:

 var offset : Vector3 = thisTransform.position - mainCamera.ScreenToWorldPoint(Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, (thisTransform.position-mainCamera.transform.position).magnitude));
 while(touched)
 {
    thisTransform.position = mainCamera.ScreenToWorldPoint(Vector3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, (thisTransform.position-mainCamera.transform.position).magnitude)) + offset;
    thisTransform.position.y = 0;
 }

The first code block works perfectly fine when using say a 90 degree camera, but that 60 degree angle throws it slightly off (and no I can't change the camera angle). Any suggestions?

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

Answer by robertbu · Apr 03, 2013 at 01:21 AM

One idea. Construct a plane parallel to your surface. You can use a real plane or you can use a mathematical plane using Unity's Plane class. When a use begins to drag the object, offset the plane upward by 1/2 of the height of the object (i.e. if it were a cube 1 unit in size, the planes would be moved upward 1/2 unit. To place the object, do a raycast against the plane and use the hit point. For a real plane, you can use Physics.Raycast(). For a mathematical plane, you can use Plane.Raycast(). Position the object at the hit point. That point should also be where position.y = 0;

Comment
Add comment · Show 3 · 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 KamiKaze425 · Apr 03, 2013 at 05:54 PM 0
Share

i'll try to figure out how to implement that. is this example similar to what you are talking about? except ins$$anonymous$$d of creating a cube and moving it, you just move the selected gameobject? http://forum.unity3d.com/threads/15802-Plane-Raycast-Example

if not, do you think you could help with an example? i'll follow up if i figure it out in the meanwhile

avatar image KamiKaze425 · Apr 03, 2013 at 07:11 PM 0
Share

pretty sure I got it working using that example and adjusting for my animations. thanks for the lead!

avatar image robertbu · Apr 03, 2013 at 07:20 PM 0
Share

The example looks fine. I too would have use the mathematical plane.

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

10 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

Related Questions

How to apply offset to touch position when dragging object 4 Answers

Manipulating Variables With Multi-Touch 1 Answer

Camera not moving 'smoothly' on drag. 2 Answers

How to rotate an object based on angles? 1 Answer

Multitouch drag object 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