Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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
2
Question by biohazard · Jun 30, 2011 at 07:37 AM · rotationphysicsrigidbody

pretty weird issue with rotating a sphere

Hey everyone, i've stumbled upon a pretty weird issue when rotating a sphere.

Even though the sphere has absolutely neither parents nor children, it seems to be rotating around something...

here's the rotation code :

 transform.Rotate(touchDeltaPosition.y * speeed,-touchDeltaPosition.x * speeed, 0,Space.World);


Also, i've already tried to attach a rigidbody and freeze x,y and z positions, no success

Comment
Add comment · Show 13
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 cregox · Jun 04, 2012 at 09:10 PM 0
Share

I've got exact same issue. In my case, it's on an object co$$anonymous$$g from a FBX. Space.world or Space.self makes no difference on its rotation whatsoever! On the editor, if I toy around with rotating on inspector, the center is clearly dislocated. If I use editor's rotation (`E` on keyboard), then it's the only place it rotates around itself. Couldn't find any kind of combination it would work on script, including making empty parents or rigidbodies. ( http://answers.unity3d.com/questions/8599/how-do-i-rotate-and-object-around-its-center-in-sc.html )

avatar image Wolfram · Jun 04, 2012 at 09:23 PM 0
Share

You generally have no way of knowing where your pivot is supposed to be. However, since we're talking about a sphere, the intended pivot is obviously in the center (assu$$anonymous$$g the scale factors are uniform). So you could use renderer.bounds.center (which is probably what the Editor is doing, if you select "Center" ins$$anonymous$$d of "Pivot" in the upper left)

avatar image Wolfram · Jun 04, 2012 at 09:24 PM 0
Share

Oh, wait, I was referring to the original question - @Cawas, please don't continue old questions with your own question. But if you want to achieve the Editor 'E' effect, use my suggestion.

avatar image cregox · Jun 04, 2012 at 09:43 PM 0
Share

@wolfram sorry about the confusion, but I'm not adding "my own" question here. It is (probably) the exact same issue, and I was hoping Eric would confirm it. Otherwise, it may be time to open another question to be "forever" unanswered (I've got many of those). I've tried your suggestion as I hinted on the link. It doesn't work. I even tried using Instantiate, to create a new object from the imported one, and that works, but I can't make the instantiated object to begin in the right position and I can't find that original position anywhere! That should tell us this is all really messed up and sounds to me like Unity bugs. - oh wait, I read it wrong as well! You said renderer not collider. I'll try it right now, but I don't think it will help given the case.

avatar image Wolfram · Jun 05, 2012 at 12:23 AM 1
Share

RotateAroundLocal is an internal and/or deprecated function you shouldn't use anyway. renderer.bounds.center does have a problem if your object consists of several objects/children, since it olny gives the center of the renderer you are accessing, not recursively. You'd hvae to write a function collecting bounds.$$anonymous$$/max recursively of your subhierarchy and find the center yourself. Using the parent to shift the pivot in the opposite direction always works, for any internal or external model, no matter where their original pivot is. Unless you're not setting it up correctly. Read the various answers explaining it.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Kacer · Jun 30, 2011 at 08:03 AM

Have you tried using space.self, instead of space.world?

though im not sure it would help.

If that doesnt work you can try the following; spawn a new gameobject, then move said gameobject to the center of your sphere, set the sphere as a child of the gameobject, then apply the rotation to the gameobject instead.

If that doesnt work, then im out of ideas.

just out of curiosity, where is the pivot of the sphere located?

Comment
Add comment · Show 5 · 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 biohazard · Jun 30, 2011 at 08:34 AM 0
Share

if you mean the XYZ rotation bows with pivot, they are in the sphere's middle, i've already tried to change the space line, that didnt help either...

how do i get a gameobject exactly to my sphere's center?

avatar image Kacer · Jun 30, 2011 at 08:43 AM 0
Share

set the gameobject as a child of the sphere, then move the gameobject to 0,0,0.

Or you can move both objects to world origin.

avatar image biohazard · Jun 30, 2011 at 09:29 AM 2
Share

this didn't work, for some weird reason the sphere (its not a generated one from unity) has it's center way too low which causes this issue...

is there a way to recalculate the center of a gameobject?

avatar image Kacer · Jun 30, 2011 at 09:36 AM 1
Share

Ohhh, now it makes more snese, what program did you use to make the sphere? (you could have told me to begin with, that you werent using the sphere from unity :P)

you just need to realign the pivot in your chosen 3D application, just move the pivot to the center of the sphere and it should be fixed.

avatar image cregox · Jun 04, 2012 at 09:12 PM 0
Share

@$$anonymous$$acer any way to do it only with scripts, without going to the "3D application"? There should be some way.

avatar image
0

Answer by cregox · Jun 05, 2012 at 12:15 AM

Wolfram did offer a nice solution, mostly already given elsewhere: use renderer.bounds.center along with `RotateAround`:

 transform.RotateAround(renderer.bounds.center, new Vector3(1, -1, 0), speeed); //  <-- why 3 e's speed?

The only problem in this solution is that we can't set the rotation to a specific value.

Here's another Wolfram's idea that will use the same renderer.bounds.center but with a parenting GameObject instead:

     GameObject myContainer = new GameObject();
     myContainer.name = "rot_" + transform.gameObject.name;
     myContainer.transform.position = renderer.bounds.center;
     myContainer.transform.parent = transform.parent;
     transform.parent = myContainer.transform;

     // now rotate myContainer at your will
     myContainer.transform.Rotate(touchDeltaPosition.y * speeed,-touchDeltaPosition.x * speeed, 0,Space.World);

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How not to make a RigidBody not go into ground when tilted foward? 1 Answer

Orbit cam and Rigidbodies aiming 0 Answers

Unity Script causing crash 1 Answer

Rigidbody.MoveRotation() Towards an object? 1 Answer

Errors with gravity switching... 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