Search Unity

Using Rotate Around Various Axis

Discussion in 'General Graphics' started by Livindaki, May 6, 2021.

  1. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
    I asked this question lately , i am trying to ask it differently .
    i have a Cylinder and on the top Surface in the center i have an empty gameobject and at the Boarder of the top surface of the cylinder i have a Red Sphere i need to make it Rotate around the empty gameobject ..
    if the Cylinder was stand at 90 Degrees it was Solved for me , cause i was used :
    transform.RotateAround(parent.transform.position,
    new Vector3(0,1,0),
    40 * Time.deltaTime);
    but the problem is the the Cylinder is not standing at 90 Degrees .

    upload_2021-5-6_0-28-39.png
     
  2. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    hi @Livindaki, have you tried using the transform.up vector? I mean rotate about cylinder.transform.up axis and emptyObject/parent?.trasform.position. Also keep in mind that doing new in the call is very slow because it has to dynamically allocate memory each time.
     
    Last edited: May 6, 2021
  3. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
    but using Vector3.up do a good result if the Cyliner is 90 Degrees
    otherwise its look like that : upload_2021-5-6_14-26-32.png upload_2021-5-6_14-27-3.png
     
  4. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    Here is an example:
    rotateCubeExample.png
     
  5. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    but do not use slow operations like something.transform.something. Cache the transforms when you can, e.g. change code to:
    Code (CSharp):
    1.     static Transform cylTrans;
    2.     static Transform cubeTrans;
    3.     static Transform sphereTrans;
    4. ...
    5.         cylTrans = cyl.transform;
    6.         sphereTrans = sphere.transform;
    7.         cubeTrans = cube.transform;
    8. ...
    9.             sphereTrans.RotateAround(cubeTrans.position,
    10.                 cylTrans.up,
    11.                 40);
    12.  
     
  6. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
  7. cosmochristo

    cosmochristo

    Joined:
    Sep 24, 2018
    Posts:
    250
    you're welcome