Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Opel Blitz · Aug 11, 2017 at 07:32 AM · roll a ball

Roll-A-Ball tutorial isn't correct/My ball won't move?

Right then. I don't pretend to be code savvy;but when following the tutorial, I noticed my ball simply would not move. I followed up to part 3, where he instructs how to make a simple rollaball game.

 using UnityEngine;
 using System.Collections;
 
 public class Playermovement : MonoBehaviour 
 {
     void FixedUpdate ();
         
             float moveHorizontal = Input.GetAxis("Horizontal");
             float moveVertical = Input.GetAxis("Vertical");
 
             Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         
     Rigidbody.AddForce(movement);

I need help! It just mysteriously doesn't work no matter how many other code snippets I use!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lahnar · May 13, 2015 at 06:14 AM 0
Share

I seem to be having a similar issue with the Roll A Ball tutorial. After follow all the previous steps easily once having saved my script and checking how the ball moves it remained motionless. Having tried several times to add small changes people suggested to the scrip to see what the issue was I received errors. going back to my original script I had no errors the ball simply did not move. I feel I have missed a step. Attached is my latest script with added Float speed and $$anonymous$$ovement * Speed.

roll-a-ball.png (26.7 kB)
avatar image EpiFouloux · Jun 10, 2016 at 08:34 AM 0
Share

$$anonymous$$aybe you can try considering that your code is completely wrong before saying such things ! This code won't EVEN CO$$anonymous$$PILE

5 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by kromenak · Oct 23, 2014 at 06:26 PM

From your code snippet, it looks like you're using incorrect function syntax (kind of surprised this code even compiles?)

You should do something like this:

 void FixedUpdate() // <-- DO NOT PUT A SEMICOLON HERE!
 {
   // Put your code between the braces.
 }

Additionally, you shouldn't use "Rigidbody" the way you're using it. You want to use "rigidbody" (lowercase) to access the instance of the rigidbody on the object, as opposed to the Rigidbody class itself.

You also need to make sure the object you're attaching this script to has a "Rigidbody" component attached to it.

If this doesn't make sense, I'd suggest checking out some Unity and C# tutorials.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Oct 23, 2014 at 06:35 PM 0
Share

This code won't even compile, so there is no way it 'would not move' In addition to the issue pointed out by @kromenak, line 14 is wrong. It should be:

 rigidbody.AddForce(movement);  

...with a lower case 'r'. And the rest of the script is missing, so we cannot verify the code. You need to go back and compare character by character your script against their script. Also, movement may not be large enough...especially if your surfaces have friction. If so, try this:

 rigidbody.AddForce(movement * 10.0f);
avatar image Opel Blitz · Oct 24, 2014 at 04:56 PM 0
Share

Co$$anonymous$$g up with so many problems. It demands that 'rigidbody' isn't a variable, even though i've seen so many other people use it. Its saying I need to remove the ()'s from around the (movement); part. Now it's saying playermovement already has a variable called 'movement'. Seriously what? This is not user friendly at all.

avatar image EpiFouloux Opel Blitz · Jun 10, 2016 at 08:37 AM 0
Share

Just look up to basic tutorials, no need to come to this forum to ask for solutions you can definetly find on your own !

avatar image Anxo · Oct 24, 2014 at 04:59 PM 1
Share

http://unity3d.com/learn/tutorials/modules/beginner/scripting

avatar image robertbu · Oct 24, 2014 at 11:36 PM 0
Share

@OpelBlitz - Without seeing your code, it is unclear what is causing issues with 'rigidbody'. Here is a fixup of your code that compiles. Note I've added a 'speed' variable.

 using UnityEngine;
 using System.Collections;
 
 public class Playermovement : $$anonymous$$onoBehaviour 
 {
     float speed = 3.5f;
 
     void FixedUpdate () {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical) * speed;
         rigidbody.AddForce(movement);
     }
 }

avatar image liuqa · Jun 09, 2016 at 11:18 PM 0
Share

This is what I've added according to the 2nd tutorial video:

using UnityEngine; using System.Collections;

public class PlayerController : $$anonymous$$onoBehaviour{

 public float speed;

 private Rigidbody rb;

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

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

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

     rigidbody.AddForce(movement * 10.0f);
 }

}

avatar image
1

Answer by iBayan · Jun 13, 2016 at 06:06 AM

Hello, I had the same problem Here what you need to do : -FIRST you have to enter this code exactly in the script

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     public float speed;
 
     private Rigidbody rb;
 
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         rb.AddForce (movement * speed);
     }
 }

-SECOND you have to click your ball from the Hierachy window and in the Inspector window select add component - physic - RigidBody (THIS IS WHAT CAUSE THE PROBLEM YOU DID NOT ADD A RIGIDBODY TO YOUR BALL THATS WHY IT WONT MOVE)

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liuqa · Jul 18, 2016 at 10:19 PM 0
Share

Already did that. Still nothing.

avatar image Joyce4255 · Sep 13, 2016 at 03:19 AM 0
Share

I did it these you mentioned. But the ball stayed motionless.

avatar image Philo_Sophia · Mar 18, 2017 at 03:50 AM 0
Share

Copied the code, my sphere is a rigid body, still won't work.

avatar image juanfer1977 · Feb 08, 2018 at 09:54 PM 0
Share

Thanks ¡¡¡ you´ve made my day ...¡¡¡ I was searching for hours, losing my $$anonymous$$d until I found and followed your advice...works great ¡¡¡¡

avatar image
1

Answer by mrh0rrible · Aug 11, 2017 at 06:53 AM

I got this to work by setting the initialization to

 public float speed = 0.0f;

I think you need to be explicit in the declaration for it to work.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Byelrathyn · Oct 06, 2017 at 10:28 PM 0
Share

This is what got it working for me when it wouldn't show the public variable in the Inspector view. Thanks!

avatar image
1

Answer by DobroAlex · Oct 22, 2019 at 06:16 PM

Okay, ultimate code solution: There seems to be the problem with speed -- it's declared but never initialized. My solution is: using UnityEngine; using System.Collections;

 public class PlayerController : MonoBehaviour {
 
     public float speed = 10.0f;
 
     private Rigidbody rb;
 
     void Start ()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate ()
     {
         float moveHorizontal = Input.GetAxis ("Horizontal");
         float moveVertical = Input.GetAxis ("Vertical");
 
         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
 
         rb.AddForce (movement * speed);
     }
 }


Or you can access speed as: rb.AddForce (movement * this.speed);

OR you may skipped part of the lesson there public varibale is changed like an object property

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Mogwyre · Mar 12, 2017 at 06:42 PM

Had the same issue with this tutorial. I'm new to coding with a rough background in js.

I commented out "public float speed;" and then multiplied the movement by 10 as someone previously suggested in this thread. It works. I think this is an error on the tutorial's side.


using UnityEngine; using UnityEngine.UI; using System.Collections;

public class PlayerController : MonoBehaviour {

// public float speed; public Text countText; public Text winText;

 private Rigidbody rb;
 private int count;

 void Start ()
 {
     rb = GetComponent<Rigidbody>();
     count = 0;
     SetCountText ();
     winText.text = "";
 }

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

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

     rb.AddForce (movement * 10.0f);
 }

 void OnTriggerEnter(Collider other) 
 {
     if (other.gameObject.CompareTag ("Pick Up")) 
     {
         other.gameObject.SetActive (false);
         count = count + 1;
         SetCountText ();
     }
 }

 void SetCountText ()
 {
     countText.text = "Count: " + count.ToString ();
     if (count >= 12)
     {
         winText.text = "YOU WON, IDIOT!";
     }
 }

}

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Roll a Ball tutorial - Pick ups stop rotating when i add more than one 1 Answer

roll the ball - player not moving. Script seems fine,Roll a ball not rolling, should I add speed ? 1 Answer

Why am i getting a Null Referencce Expectation in roll a ball? 1 Answer

camera rotate and follow the ball 0 Answers

Build failed, illegal characers in path. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges