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
1
Question by Beks_Omega · Aug 27, 2017 at 10:29 PM · rotationvector3cubeplanerotation axis

How to Rotate Plane of Cube Around its Center? (Rotate Vectors Around Point/Axis/Direction)

Hello! I am trying to create a script to deform a cube. Specifically to rotate the top and bottom planes of the cube. I know which vertices of the mesh I need, and I can rotate them, just not in the way I would like to.

Right now I start of with the cube, the direction vector in red, and the top plane in green:

Starting Cube

Then I rotate it using this code:

 //Where topRotation is how much I want the plane to be rotated
 //And Vector3.right is the red arrow (direction vector)
 Quaternion qAngle = Quaternion.AngleAxis(topRotation, Vector3.right);
 
 //Doing this for each vertice
 vertice[verticeBeingModified] = qAngle * vertice[verticeBeingModified];
 
 //Then I reset the vertices of the mesh, recalculate normals, ect

And I get something that looks like this: (when the topRotation is near 90)

Rotated Cube

So it appears that the plane is rotating around an axis in the middle of the cube, instead of one in the center of the plane. What I would like to happen is something like this:

What I would like to happen

Where the center of the plane always stays in the same location.

I hope the pictures weren't too confusing! I have looked into rotating Vector3's around points & arbitrary direction axis, but I just can't figure out what exactly I need in this situation. If anyone has any advise/ can point me in the right direction it would me very much appreciated. TY!

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 · Aug 28, 2017 at 12:22 AM

Your vertices are specified in local space coordinates of your cube object. Rotations always happens around the origin of the space where you define your positions / vectors. You would have to do:

  • offset your vertices so the new origin is at the center of your plane and not at the center of your cube.

  • rotate your vertices.

  • offset them back by the same amount as in step 1, just in the opposite direction.

Those 3 operations can be combined into a single transformation matrix. But if you're not familiar with matrices it might be easier for you to do the 3 steps manually.

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 Bunny83 · Aug 28, 2017 at 12:29 AM 0
Share

ps: the offset you need is just the center point of the plane in localspace coordinates (so relative to the cube center).

The steps are:

 v = v - c;
 v = qRot * v;
 v = v + c;

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

102 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

Related Questions

Rotating A Vector2 Input Into A Vector3 1 Answer

Rotate to face the bottom of a unit towards a planet 0 Answers

Get angle around a specified axis. 1 Answer

How can I rotate a vector direction around an arbitrary axis? 0 Answers

simple 360 degree Cube-rotation around y axis 2 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