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
0
Question by GameCherry · Apr 30, 2011 at 10:56 PM · rotationvector3rotatewheelspin

How Rotate Object To Resemble Spinning?

Hello All. I'm trying to make my water-wheel spin counter-clockwise without animation. I've tried several variants of transform.rotate but all without success.

var rvar = 100;

var pvar = 100;

function Update() {

transform.Rotate(Vector3.forward * Time.deltaTime * rvar);
    transform.position = (Vector3(1, 1, 0) / Time.deltaTime / pvar);

}

The wheel will rotate but, around some invisible point/axis that brings it around half the screen as opposed to staying stationary and just spinning. I included a transform.position to counter this but, it does not work correctly.

I've included this jpeg to better illustrate my problem. As I manually rotate the wheel around the Z rotation - the X and Y position moves in tandem, which is good because it keeps the wheel stationary....How do I code this?

alt text

Thank you for looking.

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
2

Answer by hellcats · May 01, 2011 at 03:39 AM

In-game transform-based rotation is always around the pivot point of the object (as opposed to the "center"). The pivot point is just the origin of the local coordinate system of the object, while the "center" is the geometric average of all the vertices of the mesh on the object (note that the center is not actually stored but is computed by Unity as needed). Unity lets you rotate objects using the center, but it does this by translating the center to the origin, rotating, then translating back. You can see this in the editor by watching the position coordinates while you rotate a mesh that isn't aligned with the pivot point. In game however, Unity won't do this extra translation for you, which causes the problems you are seeing.

There are two ways to fix this. The first is to change the model so that the mesh is built around the origin you want to rotate around. The other is to use Transform.RotateAround(Vector3 origin, Vector3 axis, float angle) which does the magic that the editor does to rotate around the center.

Comment
Add comment · Show 4 · 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 Joshua · May 01, 2011 at 05:24 AM 0
Share

Yeah, I'd advice using RotateAround. Or Parenting your wheel to an empty gameObject which is set to the center of your wheel and just rotate ths ins$$anonymous$$d of your wheel with the script you already have.

avatar image GameCherry · May 01, 2011 at 06:28 PM 0
Share

Thanks for the response. I read up on RotateAround but, after applying it - it did not do what I wanted. I tried parenting the "wheel" to an empty game object but, that didnt do it either. I can get the wheel to spin around empty space but, not in a waterwheel like fashion. I even went back into the 3D and reset my "pivot" point to the center but, that also did not work. I ended up just animating it in 3DS $$anonymous$$ax and reimporting it into Unity.

avatar image GameCherry · May 01, 2011 at 06:29 PM 0
Share

Perhaps, I don't fully understand rotate, rotation, and/or RotateAround. I used this RotateAround code based on the Unity resource guide:

var vox = 0;

var voy = 0;

var voz = 0;

var vax = 0;

var vay = 1;

var vaz = 0;

function Update() {

transform.RotateAround(Vector3(vox, voy, voz), Vector3(vax, vay, vaz), 20 * Time.deltaTime); } I broke the Vector3's into variables so I could test Vector3.up. forward, left, right, etc... on the fly but, like I stated earlier, I couldnt get it to do what I wanted.

avatar image Volatile · May 15, 2011 at 09:48 PM 0
Share

I too am having same problems as GameCherry. Even when resetting the pivot point in 3ds max, the problem of finding the origin/pivot point is still wrong in unity. I also tried using a empty game object as the parent to fix the problem, but no luck. So anybody else care to shed some light on this please.

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

No one has followed this question yet.

Related Questions

How do I make gameObject.transform.rotation.z equal to a set float value? 2 Answers

Rotating an object with inertia (quaternions driving me nuts) 0 Answers

Object wont rotate in the opposite direction 1 Answer

Rotating wrong 0 Answers

Rotate a gameobject like car tire 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