Search Unity

Problem with moving 2D enemy sprite.

Discussion in 'Scripting' started by EnforcerIsIt, Jun 21, 2017.

  1. EnforcerIsIt

    EnforcerIsIt

    Joined:
    Jun 21, 2017
    Posts:
    3
    So i want to move my enemy sprite downwards ,

    public float speed;

    void Start()
    {
    GetComponent<Rigidbody2D>().velocity = transform.forward * speed;
    }

    i coppied this code from a Unity tutorial, but it was getting Rigidbody and i needed Rigidbody2D so that the only change that i've made.
     
  2. EnforcerIsIt

    EnforcerIsIt

    Joined:
    Jun 21, 2017
    Posts:
    3
  3. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    like : transform.down (might be -transform.up) instead of transform.foward? :)
     
  4. Pixelith

    Pixelith

    Joined:
    Jun 24, 2014
    Posts:
    580
    Downward would be its Y Axis, so it's velocity would be going -transform.up. Rigidbody2D will only allow movement in the X and Y Axis (as far as I've used it anyways)
     
  5. EnforcerIsIt

    EnforcerIsIt

    Joined:
    Jun 21, 2017
    Posts:
    3
    transform.up worked.Thanks so much to both of you.
     
    Pixelith likes this.
  6. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    no problem, you're welcome.