Search Unity

Moving object in semi circle

Discussion in 'Scripting' started by aqeel25, Apr 17, 2019.

  1. aqeel25

    aqeel25

    Joined:
    Apr 8, 2019
    Posts:
    25
    i have a object as a cylinder and other object rectangle placed above the cylinder.Now i want to move the rectangle half around that cylinder...i mean not 360 degree but 90 degree to one side and 90 degree to other..
    is that possible...If yes then how?
     
  2. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
    If I get this correctly, what you want to do is move a rectangle to both sides of a cylinder between 90 and -90 degrees. Fro this you can either use a RotateAround(CYLINDER) or you can child the rectangle to the cylinder and rotate the cylinder.
     
    aqeel25 likes this.
  3. aqeel25

    aqeel25

    Joined:
    Apr 8, 2019
    Posts:
    25
    Actually the pink end is placed on the cylinder and i want to move this backwards and forward but as rotation around the cylinder only half of complete 360 degree ...half on side and half on other side...as a door that open to both in and outside
     

    Attached Files:

  4. ProtagonistKun

    ProtagonistKun

    Joined:
    Nov 26, 2015
    Posts:
    352
  5. bb8_1

    bb8_1

    Joined:
    Jan 20, 2019
    Posts:
    100
    Maybe this can help: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html
    U simply define point in space and axis through that point also an angle and that is it.
    In this ^^^function all parameters(point and axis are in world coordinates)
    With transform.transformPoint and transform.transformDirection u can transform from local to
    world system points and axis.
     
  6. aqeel25

    aqeel25

    Joined:
    Apr 8, 2019
    Posts:
    25
    I want my object position not changed but it only rotate as the door is at same position but only opens in or outside