Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ive got this script for the ball-roling game, it doesent work, cood any of you tell me why?

Discussion in 'Editor & General Support' started by ncoy01, May 29, 2015.

  1. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playercontroler : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movemennt = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24. }
     
  2. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Please tell what doesn't work, instead of simply saying "it doesn't work". Help people help you, if you want help.

    For one, you called your Vector3 'movemennt' and then used 'movement' in rb.AddForce.

    Computers care about consistent spelling.
     
  3. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    I am such an idiot,du, check the spelling, my computer is slow , sometimes letters got repeated wen I type
     
  4. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    but it still doesn't
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playercontroler : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24. }
    work
     
  5. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
     
  6. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    I chanced the spelling, I hit play button, is there a step I was missing?
     
  7. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    What's the part that's not working? Is there an error you're getting? Is your character not moving?

    Is your script attached to the player? Did you set the speed in the inspector?
     
  8. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    You sure you want to be adding a force to your GameObject? You'd not normally multiple a force by a speed.
     
  9. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    how do you upload a package?
     
  10. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    How's this in anyway related to your thread?
     
  11. sadsack

    sadsack

    Joined:
    May 27, 2015
    Posts:
    156
    picking on the poor guy, great fun
     
  12. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    sorry, just thought ill show you what my problem is
     
  13. ncoy01

    ncoy01

    Joined:
    May 29, 2015
    Posts:
    22
    here is my problem video, can you tell me what I am doing wrong?
     
  14. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Not picking on anyone, just trying to figure out what the problem is.

    I never saw you enter play mode in that video, so I couldn't see what actually went wrong.