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 superflyninja · Apr 03, 2015 at 08:04 AM · rotationrotate objectrotations

A very stupid rotate question

Hi all, I have an empty gameobject which is a parent to other objects. I can move the empty parent and all children move nicely with it. No problem. However its a different story when I try and rotate it. When I use transform.rotate() the object does indeed rotate, but around the pivot point and so the object moves out of position. I read that all rotations done in scripts(Im using C#) rotate around the pivot point, not the centre point. How can I tackle this? I just want to rotate the parent in one axis around its centre. Thanks

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 tanoshimi · Apr 03, 2015 at 08:28 AM

Use Transform.Rotate...?

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 superflyninja · Apr 03, 2015 at 08:38 AM 0
Share

When I use that the object rotates around the pivot not the center(as stated in the op)and as a result the object moves out of position.

avatar image tanoshimi · Apr 03, 2015 at 08:49 AM 0
Share

You also said it's an empty gameobject, so you can position it wherever you want (and reposition its children relative to it as appropriate), and all the children will rotate around that point. An empty gameobject is represented by a singular transform and has no visible mesh, so there is no sense of a "center" or "pivot" - it's just a singular position in space.

If that's not what you want then you might care to add a diagram to your question, because at the moment its unclear what the problem is.

avatar image superflyninja · Apr 03, 2015 at 09:04 AM 0
Share

ah cool. I have a set of cubes arranged to form a loop. The loop can be n-sided, all sides contain the same number of cubes.I then parent these cubes to the empty game object. I then try and rotate the empty game object and the loop looks like it moves around a non centre point. Yet if i select the empty gameobject in the editor and use the rotate widget it rotates about its centre just fine.

avatar image tanoshimi · Apr 03, 2015 at 09:41 AM 0
Share

Create an empty gameobject in your scene and add this script - it should create n cubes in a regular shape around the parent (empty) gameobject as you describe, and then rotates that object using Transform.Rotate.

You should see all the cubes rotate around the centre point?

 using UnityEngine;
 using System.Collections;
 
 public class TestRotate : $$anonymous$$onoBehaviour {
     
     private int numCubes = 20;
     private float radius = 5f;
     
     private float rotationSpeed = 5f;
     
     private Transform _trans;
     
     // Use this for initialization
     void Start () {
     
         _trans = GetComponent<Transform>();
             
         for(int i=0; i<numCubes; i++){
         
             float b = $$anonymous$$athf.PI * 2f / numCubes * i;
             GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Cube);
             temp.transform.position = new Vector3(radius * $$anonymous$$athf.Sin(b), 0, radius * $$anonymous$$athf.Cos(b));
             temp.transform.parent = this.transform;
         }
         
     }
     
     // Update is called once per frame
     void Update () {
         _trans.Rotate(new Vector3(0, rotationSpeed * Time.deltaTime, 0));
     }
 }
 

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

19 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

Related Questions

How to make a cube turn in the direction it is moving? 1 Answer

How can I rotate an object without moving it up or down? 0 Answers

Determine if the game object has completely rotated once around its centre. 1 Answer

Positions to rotations of a regular GO 2 Answers

Build rotation tool for level editor 0 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