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 j0k · Jan 09, 2015 at 01:24 PM · rotationgameobjectrotatearoundbasicprimitives

working with RotateArround

I have one cube in some point (x,y,z);

I would like to put Sphere -s into its nodes.

This script I connect with Cube.

public class HandsOnCube : MonoBehaviour {

     // Use this for initialization
     private GameObject[] PNodes;
     private Vector3[] pos;
     private Vector3 offset;
     private Quaternion offrot;

     void Start ()
     {
             offrot = transform.rotation;
             offset = transform.position - transform.localScale / 2;

             pos = new[] {
              new Vector3 (0f, 0f, 0f),
              new Vector3 (0f, 0f, 1f),
              new Vector3 (0f, 1f, 0f),
              new Vector3 (0f, 1f, 1f),
              new Vector3 (1f, 0f, 0f),
              new Vector3 (1f, 0f, 1f),
              new Vector3 (1f, 1f, 0f),
              new Vector3 (1f, 1f, 1f)
             };

             int[] inds = new [] {0,1,2,3,4,5,6,7};
             
             PNodes = new GameObject[8];

             foreach (int i in inds) {
                     PNodes [i] = new GameObject ();
                     PNodes [i] = GameObject.CreatePrimitive (PrimitiveType.Sphere);
                     PNodes [i].transform.position = pos [i] + offset + offset_def;
                     PNodes [i].transform.localScale = new Vector3 (0.2f, 0.2f, 0.2f);
                     
                     //PNodes [i].transform.RotateAround = offrot;
                     RotateGameObjArround (PNodes [i], transform.position, offrot);
                     PNodes [i].SetActive (true);

             }
         
     }

     void RotateGameObjArround (GameObject o, Vector3 aP, Quaternion Q)
     { // ap - ArroundPoint

             Vector3 angles = Q.eulerAngles;
             o.transform.RotateAround (aP, new Vector3 (1f, 0, 0), angles.x);
             o.transform.RotateAround (aP, new Vector3 (0, 1f, 0), angles.y);
             o.transform.RotateAround (aP, new Vector3 (0, 0, 1f), angles.z);
     }
 
     // Update is called once per frame
     void Update ()
     {} 

}

Poblem: if Cube rotation = (10,20,30) then Spheres are not situated in right positions. I think that I have to modify RotateGameObjArround fn, but how? Any ideas?

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 Ericool · Jan 09, 2015 at 01:31 PM

The axis are wrong the axis must be local and it has to be a normal , you can get it by doing cross product .

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 j0k · Jan 13, 2015 at 05:30 PM 0
Share

What do you mean in code? I think that Cross((1,0,0),(0,1,0)) = |a| (0,0,1).

avatar image
0

Answer by _dns_ · Jan 09, 2015 at 02:57 PM

Hi, if I understand well: you want to create objects at the positions of the vertices of the cube.

The Transform component can transform positions or rotations from the object's space to the world space. In your case: the pos[] table represent the local positions of the vertices of the cube. But in world space, those local position has other coordinates that depends on where the cube is positioned + it's scale & rotation.

Transform.TransformPoint can transform those local coordinates to world coordinates: it will use the position + rotation + scale of the transform component to do so. Here, just use

 positionOfTheSphere = transform.TransformPoint( pos[i] );


Then you can setup the scale and rotation of the sphere to anything you want.

Comment
Add comment · Show 2 · 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 j0k · Jan 13, 2015 at 05:37 PM 0
Share

That's fine! But I want to code a global transform.

avatar image _dns_ · Jan 14, 2015 at 02:11 AM 0
Share

I don't understand what you mean by "global transform", could you please give more information ?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Character Rotation Now Matching GameObject's Local Rotation 0 Answers

GameObject Rotation is always postive 0 Answers

How to rotate an object around another facing to mouse? 1 Answer

How do I rotate on a new pivot point with RotateAround? 2 Answers

Troubles instatiating a gameobject with rotation 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