Search Unity

Rotate and Move the Cube at the same time

Discussion in 'Scripting' started by kannan_unity3d, Jul 30, 2014.

  1. kannan_unity3d

    kannan_unity3d

    Joined:
    Oct 30, 2013
    Posts:
    7
    I have the cube,and able to rotate using transform.Rotate(x,y,z),?
    hw to i move at the same time? what is the differ between transform.forward and transform.translate?
    which i am gng to use?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    transform.forward is a direction, a Vector3
    transform.translate(...) is a function that moves the transform.

    you use them together

    Code (JavaScript):
    1.  
    2. var speed : float = 10;
    3. transform.translate(transform.forward * speed * Time.deltatime);
    4.  
    "translate the position of this transform along it's forward direction by speed by the time taken in this frame" if this is placed in the Update() function it will be called every frame.


    have a look at these unity script reference pages:
    http://docs.unity3d.com/ScriptReference/Transform.Translate.html
    http://docs.unity3d.com/ScriptReference/Transform-forward.html
    http://docs.unity3d.com/ScriptReference/Transform.html
     
    zDemonhunter99 likes this.