Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Roll-a-Ball PlayerController script not working

Discussion in 'Physics' started by gforster67, Apr 20, 2017.

  1. gforster67

    gforster67

    Joined:
    Apr 20, 2017
    Posts:
    10
    Good Afternoon, I am very new to Unity and to coding as well. I was following the tutorial for Roll-a-Ball and this is the code that I created for the movement script, but when I run this in Unity I get "All compilers errors have to fixed before you can enter playmode". When I downloaded Unity it is 5.6.0f3 and Visual Studio 2017.

    Any suggestions?



    [
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     public Rigidbody rb;
    7.  
    8.     void Start ()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void FixedUpdate ()
    14.     {
    15.         float moveHorizontal = Input.GetAxis("Horizontal");
    16.         float moveVertical = Input.GetAxis("Vertical");
    17.  
    18.         Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
    19.  
    20.         GetComponent rb.AddForce(movement);
    21.     }
    22.  
     
  2. gforster67

    gforster67

    Joined:
    Apr 20, 2017
    Posts:
    10
    Sorry there is an error in the code that I had to remove, but even after removing that error I am still failing.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     public Rigidbody rb;
    7.  
    8.     void Start ()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     void FixedUpdate ()
    14.     {
    15.         float moveHorizontal = Input.GetAxis("Horizontal");
    16.         float moveVertical = Input.GetAxis("Vertical");
    17.  
    18.         Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
    19.  
    20.         rb.AddForce(movement);
    21.     }
    22.  
     
  3. Deleted User

    Deleted User

    Guest

  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    If the previous poster's comment helps you fix it, that's cool. If you have further issues, could you please indicate the line number of the error (as it relates to the posted lines here in the forum). :)
     
    si1verhawlk likes this.
  5. Jofnir_IceSesh

    Jofnir_IceSesh

    Joined:
    Jan 27, 2017
    Posts:
    72
    Try changing this:
    Code (CSharp):
    1. GetComponent rb.AddForce(movement);
    To this:
    Code (CSharp):
    1. rb.AddForce(movement);
     
  6. unity_lgpxJiMCscnfGA

    unity_lgpxJiMCscnfGA

    Joined:
    Feb 6, 2020
    Posts:
    1
    Scripts
     

    Attached Files:

    si1verhawlk likes this.
  7. krakenoid

    krakenoid

    Joined:
    Aug 30, 2021
    Posts:
    2