Search Unity

Moving object along z axis

Discussion in 'Physics' started by keepStriving, Jan 30, 2016.

  1. keepStriving

    keepStriving

    Joined:
    Feb 1, 2015
    Posts:
    7
    I can't seem to move my sprite object down along the axis, I've been trying to follow the same format as the space shooter example. I've tried using Transform.Translate too and modifying transform.position directly but still can't get it to move down the z axis. Instead it seems to just go down the y axis through the camera.

    Here is my Object:


    Here is the code:
    Code (CSharp):
    1. public class Mover : MonoBehaviour {
    2.  
    3.     public float speed;
    4.  
    5.     void Start ()
    6.     {
    7.         GetComponent<Rigidbody>().velocity = transform.forward * speed;
    8.     }
    9.        
    10. }
     
  2. Fu11English

    Fu11English

    Joined:
    Feb 27, 2012
    Posts:
    258
    2D objects only move on the XY plane I believe. Plus you need to do the movement in Update or FixedUpdate if you want it to be continuous.. Start is only called once.