Search Unity

Roll a Ball game help

Discussion in 'Getting Started' started by Jackgow428, Mar 23, 2017.

  1. Jackgow428

    Jackgow428

    Joined:
    Jul 16, 2015
    Posts:
    1
    Basicly im trying to learn the wonders of unity .. but it seems some of its most basic resources are out of date or i just suck .. not letting this discourage me i decided to come to the forums . Basicly i'm trying to make the ball roll.. any help would be greatly appreciated , as well as any recommended tutorials

    Code so far

    sing UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour
    {
    public float speed;

    private Rigidbody rb;

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



    void FixUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movment = new Vector3 (moveHorizontal, 0.0f, moveVertical);

    rb.AddForce (movment * speed);

    }
    }

    i have no errors appearing .. and yet the ball still does not move

    Thanks Jack
     
    Last edited: Mar 23, 2017
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    Welcome!

    In the future, be sure to use code tags when sharing code. It makes it much more readable and has other nifty features like providing links to the API!

    One thing that immediately jumps out at me is that you've misspelled a method name. "FixUpdate" should be "FixedUpdate". Try fixing that, and if it's still not working, we can check further.
     
    Ryeath likes this.
  3. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Welcome to the boards Jack, and no you do not suck you're just in the place where everything is new ( assuming here).

    I quoted this line because technically it is correct. You did not make any errors that C# would find. You created a valid method named FixUpdate, and if Unity was to call for the method FixUpdate, the ball would roll. Alas though, Unity is calling for FixedUpdate, as Schneider21 pointed out, and when it can't find it Unity just continues on, so nothing happens.

    C# is what is referred to as a "strongly typed language", meaning it is case sensitive and unforgiving of errors.

    So the following are all valid methods -

    FixedUpdate()
    fixedUpdate()
    Fixedupdate()
    fixedupdate()
    FixeDuPdATe()
    etc....

    but Unity will only call the top one.