Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Simple question :)

Discussion in 'Scripting' started by Vlatom, Dec 25, 2010.

  1. Vlatom

    Vlatom

    Joined:
    Dec 23, 2010
    Posts:
    2
    Hi, I am new to Unity and I'd like to make an object to move with another 0.20 units far from the first object(local direction) so I use transform. position.x + 0.20 (for X and Z too). Yes it follows it but in world directions :(. How can I change it :)

    Thanks for reply!
     
  2. enragedmrt

    enragedmrt

    Joined:
    Oct 5, 2009
    Posts:
    95
    transform.Translate(transform.TransformDirection(Vector3.forward));
     
  3. Vicenti

    Vicenti

    Joined:
    Feb 10, 2010
    Posts:
    664
    transform.position += transform.forward * (units per second) * Time.deltaTime;

    transform.(forward, left, right) is always in local coordinates.
    You can also use transform.TransformDirection, but if you're just going to use Vector3.forward as the argument it's much simpler to use transform.forward.