• 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 Yoconn · Jun 17, 2018 at 06:15 AM · transform.rotate

transform.Rotate doesnt rotate at a constant speed

I followed tutorials online to make gears rotate in place and only spin the z axis, i've looked up many questions tried a million different ways. It starts off ok, but then progressively speeds up until it's a giant blur then it suddenly takes off on the y axis and shoots upward. I'm at a loss for what is going on and finally gave up and came here. Please help me out it's been 3 hours. All I want is for the z-axis to spin at a constant steady rate.

thankyou <33

 public float rotspeed = 1;
 
 void update()
 {
    run();
 }
 
 void run()
 {
    transform.Rotate(0,0,rotspeed*Time.deltaTime);
 }

Comment
Add comment · Show 2
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 seckincengiz · Jun 17, 2018 at 08:19 AM 0
Share

Your code should work, check these possible fixes;

1- Rigidbody and Collider: If your gear has a rigid body component attached it may affect your gear. Try deleting its physics components. 2- Other scripts that attached your object: $$anonymous$$ake sure gear object has only had this rotate script attached. If there is more script attached to this object then check whether they apply some kind of force to your object or not. 3- Project Settings: Try to apply your rotate script to other objects to make sure it is not related to your project settings or gravity itself.

Here is another way to make it spin

 using UnityEngine;
 
 public class Rotate : $$anonymous$$onoBehaviour
 {
     public float speed = 30;
 
     void Update()
     {
         transform.RotateAround(Vector3.zero, Vector3.forward, speed * Time.deltaTime);
     }
 }
avatar image Yoconn seckincengiz · Jun 17, 2018 at 06:58 PM 0
Share

Yeah it definitely has something to do with the rigid body, I tested it without the rigid body and it worked. But I need the rigid body, do you know if there's a way to make it constantly roll like this but with a rigid body still attached?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by PanzerPotato · Jun 17, 2018 at 07:39 PM

Oh wait, you have a rigidbody. Try setting the rigidbody to kinematic first, and if that doesn't work, try this!

Edit: MoveRotation () does work with a non-kinematic rigidbody, it's just less painful for the Physics system if kinematic.

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 Yoconn · Jun 17, 2018 at 09:24 PM 0
Share

Am i just trying to use this incorrectly? Or is it not made for rigidbody2d? (yeah i forgot to mention its rigidbody2d my bad)

public RigidBody2D playcoll; public float rotspeed; void Start() { m_EulerAngleVelocity = new Vector3(0, 0, rotspeed); } void FixedUpdate() { playcoll.$$anonymous$$oveRotation(playcoll.rotation * m_EulerAngleVelocity.z * Time.deltaTime); }

Also if rotpseed<50 it wont rotate, but if it is above 50 such as 51 is spins extremely too fast. But if i micro adjust it to 50.02 it spins fine. But if i set it to that then hit play it moves too slow. It appears i have to let it spin around on 51 for a few seconds then lower it and it moves at that speed. But that's wonky.

avatar image PanzerPotato Yoconn · Jun 17, 2018 at 09:51 PM 0
Share

(Yeah you should probably mention these things, but hey, we all make mistakes :D) But in that case, use this. As for your code, it's playcoll.$$anonymous$$oveRotation (playcoll.rotation + (plus here, not multiply) m_EularAngleVelocity.z....)

avatar image Yoconn PanzerPotato · Jun 17, 2018 at 10:03 PM 0
Share

thank you so much <333

Show more comments
avatar image
0

Answer by seckincengiz · Jun 17, 2018 at 10:09 PM

@Yoconn Disable rigid body component from your spinning object and make it follow the pivot point. This way you will have constant rotate and also realistic effect. You don't always need to use rigid body component, most of the times you should fake the physics without using physics, it is also good for performance and consistency.

So, I think this code will do the job.

 using UnityEngine;
 
 public class Rotate : MonoBehaviour
 {
     public float speed = 30;
     public Transform target;
 
     void Update()
     {
         transform.RotateAround(Vector3.zero, Vector3.forward, speed * Time.deltaTime);
         transform.position = target.position;
     }
 }

Set the pivot point of the spinning object as your target. (If you don't have a pivot point create one empty Game Object and set its position to be your new pivot) Gear will rotate with your control and it will also follow the pivot point as it should be.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

85 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

Related Questions

Recoil function: smoothly rotation 1 Answer

Excluding Y axis rotation from a vector3 variable? 0 Answers

Stopping transform.Rotate on an exact rotation value 1 Answer

transform.Rotate not rotating with conditional statement 3 Answers

Rotating an Object in Update Function 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