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 /
  • Help Room /
avatar image
1
Question by Vunpac · Sep 13, 2016 at 09:22 PM · rotationquaterniondirection

Using Quaternion orientation with a direction vector

I have a position in space and I want to shoot rays around that position (we'll say in a box like manner for this example) so say I have a default cube and I want to shoot a ray from each corner on the forward face in the forward direction of the cube, now lets say the cubes rotation is (0, 45, 45). How would I shoot rays from each corner of that cube in the forward direction?

I can't quite figure out how to use the orientation to get the 4 points around the center position. I know I can get the center of the forward face by using transform.forward * (transform.localScale.x / 2). After that the math needs the orientation information to get the proper coordinates. I don't need anyone to code it for me. I just need to understand how the math works for using the orientation.

Thanks in advance for the help!

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 Bunny83 · Sep 13, 2016 at 09:29 PM

You basically have two options:

  • Use a combination of transform.forward / right / up to get your desired starting points

  • Or what's way easier, use local coordinates and transform the final position into worldspace using transform.TransformPoint

So the 4 corners on the front face of a default cube are:

 new Vector3( 0.5f, 0.5f,0.5f); // right top
 new Vector3(-0.5f, 0.5f,0.5f); // left top
 new Vector3(-0.5f,-0.5f,0.5f); // left bottom
 new Vector3( 0.5f,-0.5f,0.5f); // right bottom

So just run them through transform.TransformPoint() and you get the appropriate worldspace position. TransformPoint does apply the rotation, scale and position of the transform.

edit

In case you don't have a transform that faces your desired direction but only a Quaternion you have to do the the 3 things manually. So first multiply / scale those 4 local points with your desired scale. You can use Vector3.Scale for that. Once the local vectors have to proper length you would rotate them using the quaternion. Finally add the result to a worldspace center position.

 var worldSpacePoint = worldSpaceCenter + quat * Vector3.Scale(yourLocalPoint, yourScaleVector);
Comment
Add comment · Show 1 · 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 Vunpac · Sep 14, 2016 at 11:52 PM 0
Share

Also thanks for the equation in the edit, it's exactly what I needed!

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

65 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

Related Questions

Determining if my target is standing upright 4 Answers

How can I find direction with known 2 projection angles on xz and yz planes? 2 Answers

The direction my camera is rotating should indicate the direction my object facing 0 Answers

Unity 3D C# - Rotation To Slope Of Terrain 0 Answers

Rotating an Object (To Face Another Object) Only on X and Y Axis 3 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