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
1
Question by IPS · Feb 19, 2013 at 02:44 PM · c#rotateaxispivot

Rotating Cuboid Around Pivot

Hi Guys, I'm looking to rotate my cuboid around a pivot point. I was wondering how to do this (as shown in image(green is the pivot point)) so it rotates around the pivot point and also stops at the 90 degrees. I'm also looking to find a way to do it without setting a gameobject as a child because it will be difficult when I start adding more axis. alt text

Thanks to anyone who can help,

IPS

pivoting.png (12.9 kB)
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
0

Answer by flaviusxvii · Feb 19, 2013 at 03:24 PM

I suppose you could move all of the vertexes of the mesh so that that corner is the origin in model space. Then when you rotated the transform it would rotate around that point.

It would get dicey if you want to rotate around multiple axes though.

You could also do the math and figure out the series of positions and rotations necessary to frame-by-frame "fake" a rotation like this. So the object itself would still rotate around it's center, but you'd move it each time you rotate so that it would appear to rotate around that pivot.

Without knowing your use case it's hard to tell what's the best option.

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 IPS · Feb 19, 2013 at 03:37 PM 0
Share

Hi flavi,

I don't think I can create that because of the problem it would have with multiple axes.

This is the sort of thing I'm looking to create: http://www.coolmath-games.com/0-bloxorz/index.html

Any ideas?

avatar image
0

Answer by robertbu · Feb 19, 2013 at 04:11 PM

You can use either Transform.RotateAround(), or Quaternion.AngleAxis() to do an angle/axis rotation. You specify the point (i.e. the corner of the cube) and the axis (i.e. the edge) to rotate around. With a cuboid, both are easy to calculate especially if you keep the cube axis aligned. Note the direction of the axis of rotation vector matters.

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 IPS · Feb 19, 2013 at 04:21 PM 0
Share

Ahah, so how exactly would could I translate RotateAround() into code as I need to specify exact point to rotate around (-1,0.5,0 - the green point) and I'm not quite sure how to do that.

avatar image robertbu · Feb 19, 2013 at 04:39 PM 1
Share

I'm assu$$anonymous$$g the coordinate is local to the cube. So for an immediate rotation it will be something like (untested):

 v3Pos = new Vector3(-1.0f,0.5f,0.0f);
 v3Pos = transform.TransformPoint(v3Pos);
 transform.RotateAround(v3Pos, Transform.right, 90.0f);

The point is a world coordinate. I use Transform.right so that the vector will remain accurate for that rotation even if you rotate the cube every which way.

avatar image IPS · Feb 19, 2013 at 05:12 PM 0
Share

Great! Now it's fixed with the subtracting of the v3Pos = transform.TransformPoint(v3Pos); for some strange reason it made the cuboid enter warp speed. But other than that its working.

Thanks!

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

14 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

Related Questions

Change rotation axis when importing from Maya 2 Answers

C# Rotate More than Two GameObjects 1 Answer

Finding Edges 1 Answer

Rotate object 1 Answer

Functions via camera rotations... 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