Search Unity

Space Shooter tutorial 'bolt' script

Discussion in 'Scripting' started by serbusfish, Dec 27, 2016.

  1. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    247
    I am new to Unity and am running through the Space Shooter tutorial. I have manage to follow it OK up to step 6, I am now having trouble getting the laser 'bolt' to move as the script commands seem to be different.

    This is the script used in the original video:

    public class Mover : MonoBehaviour
    {
    public float speed;

    void Start ()
    {
    rigidbody.velocity = transform.forward * speed;
    }
    }


    I have looked at the document that details the changed for Unity 5.x and this is what I now have:

    public class Mover : MonoBehaviour
    {

    public Rigidbody rb;

    void Start()
    {
    rb = GetComponent<Rigidbody>();
    rb.velocity =

    }
    }

    I dont understand how I set the speed with this new script? With the old script the speed option will appear inside the project. The document does not say what to put after rb.velocity =.
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
  3. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    247
    Thats great cheers the script now works and 'speed' appears in my project. However I am wondering something else now, regarding this: 'rb.velocity = transform.forward * speed;' the bolt travel along the blue axis, how can I make it travel along the green axis?
     
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You mean the y axis? Change transform.forward to transform.up, but this should be easy, go watch more tutorials
     
  5. serbusfish

    serbusfish

    Joined:
    Dec 27, 2016
    Posts:
    247
    Thank you :) I will watch other tutorials, this is the first one I decided to try.