Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 dtilgner · Mar 20 at 05:17 PM · scripting problemvrvector3planenormals

Get point in plane where the normal crosses a GameObject in local space

Hello, I am developing a VR game where I want to steer a boat using a steering wheel. Therefore I grab the wheel with a controller and want to turn the wheel on one axis (as wheels do) according to the controller movement.

My plan for it was to create a Vector3 plane in the script, which resembles the plane of the wheel. Then I would take the normal of it and use the Vector3.ProjectOnPlane()-Method to find the point on the plane to resemble the controller. When I have the point, I would rotate the steering wheel to this position. This procedure seems pretty complex and I don't even know how to create a plane in local space (so that it can rotate and move with the ship).

So my question is: Is there a better way of achieving this and if no, how could my solution be implemented?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Master109 · Mar 20 at 06:03 PM

The following might work assuming the pivot point of the wheel is at the center and the top is facing up at rotation (0, 0, 0):

 wheelTrs.up = controllerTrs.position - wheelTrs.position;

The following will work if the previous assumptions were true:

 wheelTrs.rotation = Quaternion.LookRotation(wheelTrs.forward, controllerTrs.position - wheelTrs.position);

Please comment if the previous assumptions were false and I will let you know how to proceed.

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 dtilgner · Mar 21 at 12:26 PM

Hey @Master109 , thanks for the fast reply :) The pivot point is indeed at the center, but the top isn't facing up. The parent of the wheel is slightly tilted, but the wheel itself where the script is attached has a rotation of (0,0,0). Nevertheless I tried your approach - and it works somehow :D the wheel is rotating around the Z axis - but I need it to be rotated around Y. I somewhat understand what you are doing, but I dont get how to adjust this line to do what I want to do. I tried using wheelTrs.up and wheelTrs.right, but then the wheel is just bugging around. Other adjustments that seemed to be logic didn't do what I wanted either. What am I missing?alt text

Also I have the player grabbing the wheel anywhere and now i want him to start from this position to turn, but I guess I just need to add the angle difference then.


wheel.png (132.0 kB)
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 Master109 · Mar 23 at 08:30 PM 0
Share
 using UnityEngine;
 
 public class Wheel : MonoBehaviour
 {
     public Transform trs;
     public Transform controllerTrs;
     bool isGrabbed; // You will need to set this variable
     bool previousIsGrabbed;
     Vector3 previousGrabPosition;
 
     void Update ()
     {
         if (isGrabbed)
         {
             Vector3 grabPosition = controllerTrs.position;
             float grabAngle = Vector3.SignedAngle(grabPosition, trs.position, trs.up);
             if (!previousIsGrabbed)
                 previousGrabPosition = grabPosition;
             trs.Rotate(Vector3.up * Vector3.SignedAngle(previousGrabPosition - trs.position, grabPosition - trs.position, trs.up));
             previousGrabPosition = grabPosition;
         }
         previousIsGrabbed = isGrabbed;
     }
 }
avatar image dtilgner · Mar 27 at 07:31 PM 0
Share

Thanks for the response, I tried that solution. But somehow this does not work in my case. I will go on trying and your answer helped me understanding some key mechanics. :) If I find a solution or have a more specific question, I will post it here.

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

301 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

orizontal slider to control a plane's y transform variable 1 Answer

Imparting Physics in only certain planes of motion 1 Answer

Local Euler Angles not Rotating GameObjects 1 Answer

(Steam VR / Vive) Rigidbody moving in only one direction after collision 1 Answer

Assign Object to Unity Event (Select Entered) of Prefabbed Game Object with "XR Grab Interactable" 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