Search Unity

Space Shooter

Discussion in 'Scripting' started by auzzymo, Nov 19, 2017.

  1. auzzymo

    auzzymo

    Joined:
    Nov 19, 2017
    Posts:
    17
    Hi all,

    I'm very new to programming (less than a month) and have been running through the tutorial Space Shooter.
    As a few changes have happened since the release of the SS tutorial I am a little bit unsure where to go. I have used the updated pdf but Im still unsure because it wont move for me.

    Here is the code that I have written:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour {

    public float speed;
    float moveHorizontal;
    float moveVertical;
    private Rigidbody rb;

    // Use this for initialization
    void Start () {

    rb = GetComponent<Rigidbody> ();

    }

    // Update is called once per frame
    void FixedUpdate () {

    moveHorizontal = Input.GetAxis ("Horizontal");
    moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement * speed;


    }
    }

    Any feedback would be wonderful, thank you :)
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Are you getting any errors. I can't see anything wrong with the code. The only thing here is, speed hasn't been assigned a value.
     
    Last edited: Nov 20, 2017
    auzzymo likes this.
  3. auzzymo

    auzzymo

    Joined:
    Nov 19, 2017
    Posts:
    17
    Hi,
    Thanks for replying. No there's no errors, and the public float speed has been increased up to 10 and no movement.
    Spent about 4-5 hours yesterday scratching my head on this.
    I was thinking maybe I've locked the space ships position in the inspector but all the axis are free.
    So to be clear the code is ok?
    I'll build it all over again I suppose.
     
  4. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    No, I can't find anything wrong with the code. You have to have isKinematic set to false in the collider if you use velocity for movement.
     
    auzzymo likes this.
  5. auzzymo

    auzzymo

    Joined:
    Nov 19, 2017
    Posts:
    17
    I came back on here to repost that I'd fixed it, I just read your post too. And guess what it was? Is Kinematic was active....
    Thanks for helping me out, it works fine now :) :)