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 gabrielstuff · Aug 27, 2013 at 09:23 PM · rotationlocalworldtranslationtween

Rotation and Translation children parent and tween

Hi !

I have a group of GameObject which belong to an empty GameObject. This emtpy GameObject rotate with this simple function :

 transform.RotateAround (_bounds.center, Vector3.up, 20 * Time.deltaTime);

The _bounds variable is private and calculate dynamically depending on the geometrical movement of the children. Thus the rotation is always centered.

The problem comes when I add tween to my children. Indeed each children move independently from left to right, up and down, back and forth.

 HOTween.To(transform.GetChild(i), 10, new TweenParms()
                         .Prop("position", new Vector3(transform.GetChild(i).position.x + Random.Range(-5.0F, 5.0F), transform.GetChild(i).position.y + Random.Range(-5.0F, 5.0F), transform.GetChild(i).position.z + Random.Range(-5.0F, 5.0F)), false) // Position tween (set as relative)
                         .Loops(-1, LoopType.Yoyo) // Infinite yoyo loops
                         .Ease(EaseType.EaseInOutQuad) // Ease
                         .OnUpdate( OnTweenUpdate )
                         .OnStepComplete(moveComplete, transform.GetChild(i).name) // OnComplete callback
                     );


The tween are instantiate at start. Bellow you will find full code. The issue arise when both instruction run simultaneously. The tween update the position and the update update the rotation of parent which update the position of of children.

What I'd like is rotate AND move for each of my single children.

Any help would be much appreciate.

 using UnityEngine;
 using Holoville.HOTween;
 using System.Collections;
 using System.Collections.Generic;
 using Vectrosity; 
 
 
 public class GenerateLines : MonoBehaviour {
     private List<VectorLine> connectionList;
     private int childrenNumber;
     private Bounds _bounds;
         
     [Range(0.0f, 360)]
     public float rotationY;
     
     public Material lineMaterial;
     [Range(0.1f, 10.0f)]
     public float stroke;
     
     //private Material materialLine;
     
     void Start() {
         // First find a center for your bounds.
         calculateCenter();
         connectionList = new List<VectorLine>();
         HOTween.Init(true, true, true);
         
         childrenNumber = this.transform.childCount;
         var linePoints = new Vector3[2];    
         if(childrenNumber >= 2){
             for(int i = 0; i < childrenNumber; i++){
                         linePoints[0] = transform.GetChild(i).position;
                         linePoints[0].z +=  0.01f;
                         var lineName = gameObject.name + "-line-" + i;
                         if(i < childrenNumber - 1){
                             linePoints[1] = transform.GetChild(i+1).position;
                         } else {
                             linePoints[1] = transform.GetChild(0).position;
                         }
                         linePoints[1].z +=  0.01f;
                         connectionList.Add(new VectorLine(lineName, linePoints, lineMaterial, stroke));
                         connectionList[i].Draw3D();
                         
                     
                     HOTween.To(transform.GetChild(i), 10, new TweenParms()
                         .Prop("position", new Vector3(transform.GetChild(i).position.x + Random.Range(-5.0F, 5.0F), transform.GetChild(i).position.y + Random.Range(-5.0F, 5.0F), transform.GetChild(i).position.z + Random.Range(-5.0F, 5.0F)), false) // Position tween (set as relative)
                         .Loops(-1, LoopType.Yoyo) // Infinite yoyo loops
                         .Ease(EaseType.EaseInOutQuad) // Ease
                         .OnUpdate( OnTweenUpdate )
                         .OnStepComplete(moveComplete, transform.GetChild(i).name) // OnComplete callback
                     );
             }        
         }
     }
     
     void OnTweenUpdate(){
         Debug.Log("updateTween");
         calculateCenter();
         
         transform.RotateAround (_bounds.center, Vector3.up, 20 * Time.deltaTime);
     }
     
     void Update() {
         childrenNumber = this.transform.childCount;
         if(childrenNumber >= 2){
             if(connectionList.Count < childrenNumber){
                 Debug.Log(connectionList.Count);
             } else {
                 for(int i = 0; i < connectionList.Count; i++){
                         connectionList[i].points3[0] = transform.GetChild(i).position;
                         if(i < childrenNumber - 1){
                             connectionList[i].points3[1] = transform.GetChild(i+1).position;
                         } else {
                             connectionList[i].points3[1] = transform.GetChild(0).position;
                         }
                         connectionList[i].points3[0].z += 0.2f; 
                         connectionList[i].points3[1].z += 0.2f; 
                         connectionList[i].lineWidth = stroke;
                         connectionList[i].Draw3D();
                 }
             }
         }
     }
     
     void calculateCenter(){
         Vector3 runtimeCenter = Vector3.zero;
         
         foreach (Transform child in transform)
         {
             runtimeCenter += child.gameObject.renderer.bounds.center;   
         }
         runtimeCenter /= transform.childCount; //center is average center of children
 
         if(_bounds != null){
             _bounds.center = runtimeCenter;
             _bounds.size = Vector3.zero; 
         } else {
             _bounds = new Bounds(runtimeCenter,Vector3.zero); 
         }
         
         foreach (Transform child in transform)
         {
             _bounds.Encapsulate(child.gameObject.renderer.bounds);   
         }
     }
     
     void moveComplete(TweenEvent data){
         if ( data.parms != null ) {
             Debug.Log( data.parms[0] ); // outputs 1
           }
         Debug.Log("complete");
     }
     
     void OnMouseDrag() {
         renderer.material.color -= Color.white * Time.deltaTime;
     }
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

World and Local Axis out of Alignment 1 Answer

Apply a Rotation in World Space based on Quaternions 2 Answers

bone rotations changed in 4.3.2 inspector? 0 Answers

Why does the object alignment only work when the object isn't rotated? 2 Answers

an ignorant's trigonometry woes: rotate a transform around an axis 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