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 TaintedLemon · Jun 17, 2011 at 05:28 AM · dragplaneintersectperpendicular

Dragging object on 2D plane from perpendicular view

Dear Internet,

I have an object on a 2D plane which I wish to drag along this plane. The plane is not infinite when it comes to placing the object. At first I performed a simple Raycast of the input to determine the hit position on the plane, and then moved the object to this position.

The problem with this approach is that I am often having to view the 2D plane perpendicular, such that the plane is completely flat and so is not seen by the user. For example the plane is on the z-x axis and the camera is also on the z-x axis, looking along the z axis. In this case the ray either misses the plane, or intersects the plane at a very far distance, causing the dragged object to move to an odd position when I cast it to the nearest valid point.

I tried creating a two step process, where the ray is cast onto another plane, facing the camera, centred at the object. Then from this hit position cast on to the original plane. If the camera is perpendicular this works.

An example of this working is: alt text

The camera is facing the plane perpendicular, the input is below the plane. The original ray hits the red plane facing the camera and then the second ray hits the dragged destination point on the yellow plane.

The problem is that this two step process then causes weird behaviour when the camera is not perpendicular, as the first ray can hit the camera-facing plane in the distance.

Here is an example of this not working: alt text

The object is in the distance, thus the red plane facing the camera is in the distance. The original ray hits this and then, when projected again onto the final plane, the dragged location is completely incorrect.

Essentially I need a way to drag an object around a non-infinite plane from any camera angle, including perpendicular. Either the process needs to somehow blend between the two options, or a different approach is needed.

Any suggestions / advice is much appreciated :D

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
1

Answer by Chris D · Jun 17, 2011 at 05:56 PM

A simple way to get around the perspective change would be to use straight mouse input instead of raycasts. So something like:

 var horizontalSpeed : float = 2.0;
 var verticalSpeed : float = 2.0;

 function Update () {
     if (Input.GetMouseButton(0)){
         // Get the mouse delta. This is not in the range -1...1
         transform.position.x += horizontalSpeed * Input.GetAxis ("Mouse X");
         transform.position.y += verticalSpeed * Input.GetAxis ("Mouse Y");
     }
 }

(it's just a modified mouse-look script from the scripting guide) and just add an if-statement to constrain it to your plane's extents.

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 TaintedLemon · Jun 17, 2011 at 10:16 PM 0
Share

The problem with this approach is it doesn't take into account the direction of the camera. And even if it did, the object wouldn't line up under the input position - so would be somewhat unintuitive.

avatar image Chris D · Jun 17, 2011 at 10:22 PM 0
Share

Yup, but I thought maybe you could use a different approach. How free is the camera to move around your scene?

avatar image TaintedLemon · Jun 17, 2011 at 10:25 PM 0
Share

Completely. They can view the scene plane from any angle with any orientation.

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

2 People are following this question.

avatar image avatar image

Related Questions

Intersection point of mouse with ZX plane 1 Answer

can I drag out the scale of a plane? 1 Answer

Help to fix my drag code [SOLVED] 1 Answer

hot to use raycast 2 Answers

Click and drag a plane 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