Search Unity

How to rotate and move a gameobject ?

Discussion in 'Scripting' started by zyonneo, Jun 24, 2020.

  1. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    386
    I need a cylinder in a circular shape(disc2 - screenshot) to rotate and move in both forward and backward similar to wheels motion.This happens when I rotate another disc(disc1) towards right and left(in VR).How to rotate and move disc2 according to the movement of disc1.The values I obtain from rotating disc1 is an outangle which is the range of (-90 to +90).Should I convert it to some float value.



    Code (CSharp):
    1. public void RotateRight()
    2.     {
    3.         circularInput = cd.outAngle;
    4.         Debug.Log("Circular Input Values " + circularInput);
    5.  
    6.         float deltaMovement = circularInput * speed * Time.deltaTime;
    7.         this.transform.Translate(new Vector3(0f, deltaMovement, 0f));
    8.     }
    9.  
    10.     public void RotateLeft()
    11.     {
    12.         circularInput = cd.outAngle;
    13.         Debug.Log("Circular Input Values " + circularInput);
    14.  
    15.         float deltaMovement = circularInput * speed * Time.deltaTime;
    16.         this.transform.Translate(new Vector3(0f, -deltaMovement, 0f));
    17.     }
    The disc2 image I have uploaded which is required to rotate and move.Where should I give the deltamovement in y axis(local) or with respect to x axis(world).



    EDIT - The movement is not smooth.It is jumping from one position to another when I complete the rotation of disc1.
     
    Last edited: Jun 24, 2020
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689