Search Unity

I can’t make the Arm - Base rotate in Axis "Y"

Discussion in 'Editor & General Support' started by paco morales, Jan 10, 2011.

  1. paco morales

    paco morales

    Joined:
    Dec 30, 2010
    Posts:
    12
    Hello Everyone :)

    I’m learning with this Robot Toy.... But I can't make the Arm Base rotate in Axis Y.... I didn’t have problems with the other parts...I have several days trying to fix it, but I can't....

    I can't make it rotate in axis “Y” Any help please!

    Here it is the file and you can see the image.





    Thanks in advance

    Keyboard:

    Base Arm “R” “Y”
    Arm 1 “A” “D”
    Arm 2 “Q” “E”
    Hand “Z” “C”
     

    Attached Files:

    Last edited: Jan 11, 2011
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Any chance you could post some code, just for those who don't get around to downloading your project (or whatever the attachment is)?

    What you describe should be a simple matter of proper object parenting and applying appropriate rotations in local space; if it's not working, I'm guessing it's simply because you're handling the rotations in the wrong way. If we can see the scripts that manage the rotation, I imagine someone might be able to spot the problem even without seeing the project itself.

    (Also, here is a link to your UA post on the same subject.)
     
    Last edited: Jan 10, 2011
  3. paco morales

    paco morales

    Joined:
    Dec 30, 2010
    Posts:
    12
    Hello Jesse!

    Here it is the screenshot of the hierarchy of the Arm with the parenting. Each segments is rotating in Local Axis.

    And here are the scripts for each segment.

    Thanks

    [/IMG]



    Base Arm Script:

    Code (csharp):
    1. var gunSpeedNeg: int = -40;
    2. var gunSpeedPos: int = 40;
    3. function Update () {
    4.  
    5.  
    6.     if(Input.GetKey("r")){
    7.     transform.Rotate(Vector3.right* gunSpeedNeg* Time.deltaTime);
    8.    
    9.                         }
    10.     if(Input.GetKey("y")){
    11.     transform.Rotate(Vector3.right* gunSpeedPos* Time.deltaTime);
    12.                         }
    13.    
    14.     }
    15.  
    16.  
    Arm 1 Script:


    Code (csharp):
    1. var gunSpeed : float = 40;
    2.  
    3. private var rotation : Quaternion = Quaternion.identity;
    4. private var left : Quaternion = Quaternion.AngleAxis(-150, Vector3.up);
    5. private var right : Quaternion = Quaternion.AngleAxis(30, Vector3.up);
    6.  
    7. function Start ()
    8. {
    9.     // This piece of code will allow you to remember the origin.
    10.     rotation = transform.rotation;
    11.     left = rotation * left;
    12.     right = rotation * right;
    13. }
    14.  
    15. function Update ()
    16. {
    17.     var speed = gunSpeed * Time.deltaTime;
    18.  
    19.     if(Input.GetKey("a"))
    20.     {
    21.         rotation = Quaternion.RotateTowards(rotation, left, speed);
    22.     }
    23.  
    24.     if(Input.GetKey("d"))
    25.     {
    26.         rotation = Quaternion.RotateTowards(rotation, right, speed);
    27.     }
    28.  
    29.     transform.rotation = rotation;
    30. }
    31.  
    Arm 2 Script:

    Code (csharp):
    1. var gunSpeed : float = 40;
    2.  
    3. private var rotation : Quaternion = Quaternion.identity;
    4. private var left : Quaternion = Quaternion.AngleAxis(-15, Vector3.up);
    5. private var right : Quaternion = Quaternion.AngleAxis(90, Vector3.up);
    6.  
    7. function Start ()
    8. {
    9.     // This piece of code will allow you to remember the origin.
    10.     rotation = transform.rotation;
    11.     left = rotation * left;
    12.     right = rotation * right;
    13. }
    14.  
    15. function Update ()
    16. {
    17.     var speed = gunSpeed * Time.deltaTime;
    18.  
    19.     if(Input.GetKey("q"))
    20.     {
    21.         rotation = Quaternion.RotateTowards(rotation, left, speed);
    22.     }
    23.  
    24.     if(Input.GetKey("e"))
    25.     {
    26.         rotation = Quaternion.RotateTowards(rotation, right, speed);
    27.     }
    28.  
    29.     transform.rotation = rotation;
    30. }
    Hand Script


    Code (csharp):
    1. var gunSpeed : float = 40;
    2.  
    3. private var rotation : Quaternion = Quaternion.identity;
    4. private var left : Quaternion = Quaternion.AngleAxis(-25, Vector3.up);
    5. private var right : Quaternion = Quaternion.AngleAxis(80, Vector3.up);
    6.  
    7. function Start ()
    8. {
    9.     // This piece of code will allow you to remember the origin.
    10.     rotation = transform.rotation;
    11.     left = rotation * left;
    12.     right = rotation * right;
    13. }
    14.  
    15. function Update ()
    16. {
    17.     var speed = gunSpeed * Time.deltaTime;
    18.  
    19.     if(Input.GetKey("z"))
    20.     {
    21.         rotation = Quaternion.RotateTowards(rotation, left, speed);
    22.     }
    23.  
    24.     if(Input.GetKey("c"))
    25.     {
    26.         rotation = Quaternion.RotateTowards(rotation, right, speed);
    27.     }
    28.  
    29.     transform.rotation = rotation;
    30. }
     
    Last edited: Jan 11, 2011
  4. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    Can you repost your code using 'code' tags and proper indentation? (Assuming you haven't already figured it out, that is.)
     
  5. paco morales

    paco morales

    Joined:
    Dec 30, 2010
    Posts:
    12
    Okay Jesse no problem, thanks
     
  6. juanmanuel

    juanmanuel

    Joined:
    Nov 3, 2009
    Posts:
    9
    Paco, you are using the same key to move two different pieces of the robot.


    That is, the E key is used for Arm2 and Hand.
     
  7. paco morales

    paco morales

    Joined:
    Dec 30, 2010
    Posts:
    12
    Thanks Juan,

    That was only a mistake in the text, I'm going to try to change the Axis in 3D Max and re-import the model to Unity
     
  8. paco morales

    paco morales

    Joined:
    Dec 30, 2010
    Posts:
    12
    Hello,

    I fixed the rotation in the correct Axis, but the arm extension rotates keeping the same orientation don't change (always see to the same direction).

    (The Base's Arm rotates well, but the Arm as a "children" rotates keeping the same orientation)

    Please take a look to the image.

    [/IMG]

    Here it is the Script I'm using.


    Code (csharp):
    1. var gunSpeedNeg: int = -40;
    2. var gunSpeedPos: int = 40;
    3. function Update () {
    4.  
    5.  
    6.     if(Input.GetKey("r")){
    7.     transform.Rotate(Vector3.right* gunSpeedNeg* Time.deltaTime);
    8.    
    9.                         }
    10.     if(Input.GetKey("y")){
    11.     transform.Rotate(Vector3.right* gunSpeedPos* Time.deltaTime);
    12.                         }
    13.    
    14.     }

    Any advice is welcome.
     
    Last edited: Jan 11, 2011