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 /
avatar image
1
Question by Crashmast · Apr 08, 2014 at 11:52 AM · errortutorialroll a ball

Roll a Ball tutorial error

Here goes a rally stupid question, but I've tried everything I could thing of and everything I've read on here, and nothing works. I'm currently doing the 'Roll a Ball' tutorial and I'm onto the 2nd video, around 9:30 in. Despite typing word for word what the tutorial says, and after fixing it with the help from other questions, I still get this error:

"Assets/Scripts/playerController.cs(13,35): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)' "

It's driving me crazy... I've corrected all the spelling mistakes I could see and read about on here. Typing rigidbody in lowercase made the error stop. But I can't move the ball.

Heres my code: using UnityEngine; using System.Collections;

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

Thanks.

Comment
Add comment · Show 1
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 PhoenixFF · Mar 07, 2015 at 06:18 AM 0
Share

Are you using Unity 4 or Unity 5? If using Unity 5 the tutorial code won't work.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Graham-Dunnett · Apr 08, 2014 at 11:54 AM

 rigidbody.AddForce(movement);

(Note the lowercase r. RigidBody is a class, rigidbody is a member of type RigidBody that belongs to the game object.)

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 MDCT · Sep 01, 2014 at 08:01 AM 0
Share

still doesnt work for me :(

avatar image
1

Answer by setho246 · Mar 16, 2015 at 08:27 AM

Hey Crashmast,

If your using Unity 5, then here is your problem:

The tutorial is outdated, so you need to save the Unity Mono-develop, then close it.

Return to unity, in the Assets options drop-down box (up the top, near File, Edit etc.), click Run API Updater.... It will recommend that you make an backup, up to you whether or not you do.

This should fix your problem.

If your using unity 4 or later, then I can't help you sorry.

Setho246

Comment
Add comment · Show 3 · 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 ElieSaad · Mar 18, 2015 at 11:21 PM 0
Share

Hey @sethose246 do you know any up to date tutorials??

avatar image setho246 · Mar 19, 2015 at 09:22 AM 0
Share

Unfortunately no @ElieSaad, but I haven't been spending much time at all looking, as I lead quite a busy life, and Unity was just something to keep myself occupied whilst on the bus, on a plane, etc. If you happen to find any, though, I would be grateful if you could please tell me

Thanks,

Setho246

avatar image mastermind1018 · Aug 10, 2015 at 06:41 PM 0
Share

Hello @Setho246,

Im not sure why but it wont let me use the Run API Updater for some reason. Any fixes?

Thanks

avatar image
0

Answer by Kiwasi · Mar 19, 2015 at 09:54 AM

The correct syntax in Unity 5 is

 GetComponent<Rigidbody>().AddForce(movement);

You'll also have some trouble with GUIText later in the series. See this video for a fix.

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 jf192 · Mar 25, 2015 at 08:24 PM 0
Share

Thanks a lot for this. I had the same problem and I was beginning to get really frustrated with it not working.

It's annoying that the tutorials haven't been updated but I suppose that forcing you to adapt is a good learning process anyway, considering I'm a total beginner when it comes to such things.

avatar image
0

Answer by nidhi_30 · Jan 31, 2016 at 02:35 PM

using UnityEngine; using System.Collections;

public class playercontroller : MonoBehaviour {

 //public float speed;

  public 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 );
     
     GetComponent<Rigidbody>().AddForce(movement);

 }

} my code is this. and problem is :Cleaning up leaked objects in scene since no game object, component or manager is referencing them MonoScript has been leaked 1 times.

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

30 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 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

Multiple Cars not working 1 Answer

Error when I try to run the build in tutorial (roll a ball, tanks, and etc.) 0 Answers

roll-a-boll tutorial-rotator error 1 Answer

Error CS1502 Help! 1 Answer

I'm doing the Roll-A-Ball tutorial and I entered the Player Controller script exactly as the tutorial has it, but I put mine in Unitron and errors are occurring that I don't know how to fix. 2 Answers


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