• 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
Question by JPGoal · Mar 12, 2015 at 02:51 PM · errorrigidbodyrigidbody2daddforce

Rigidbody.AddForce not being detected

When I am inputting lines to add a force in both 2d and 3d, addforce is said not to exist in the directories and when it comes to running. I keep getting the CS0120 Error. I reinstalled the program with hopes of it being just a glitch in the installation but it still appears to be missing. Edit:

    void Update () {
         if(Input.GetKey(KeyCode.D)){
             Rigidbody2D.AddForce (Vector2.right);
         }
 }

I just tried it with a basic line added the component to a sprite to see if it would work but for some reason it just doesn't

Comment

People who like this

0 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 AlwaysSunny · Mar 12, 2015 at 05:05 AM 0
Share

Show us your code with enough context to see where it is and what you're doing with it. Format all pasted code with the 101010 button.

avatar image snobis · Mar 12, 2015 at 04:12 PM 0
Share

I have the same problem too. When i write Rigidbody.AddForce (vector3) for exemple, the AddForce is not recognize! Any suggestions?

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by tanoshimi · Mar 12, 2015 at 03:19 PM

Rigidbody is the class. You want the instance of the class. And Capitalisation matters: AddForce not addforce.

 GetComponent<Rigidbody2D>().AddForce (Vector2.right);
Comment
JPGoal

People who like this

1 Show 2 · 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 JPGoal · Mar 12, 2015 at 03:48 PM 0
Share

Thanks for the suggestion but it doesn't seem to work either, I get the same error and message. The capitalization is as I've written it so it shouldn't have been a problem either.

avatar image JPGoal · Mar 12, 2015 at 05:05 PM 0
Share

Nevermind, I just got your method to work, thanks, it took some fanagling as when I used my original code with a lowercase r for rigid body, unity restructured it since it was thought to be in an older format and it spat out this which worked

 void Update () {
         if (Input.GetKey (KeyCode.W)) {
             GetComponent<Rigidbody2D>().AddForce = Vector2.up * speed;
                 }

So Thanks For the Help!

avatar image

Answer by HolBol · Mar 12, 2015 at 02:53 PM

Well addforce won't be found because it's AddForce- case sensitive. Also, you don't seem to be giving a value to the amount. Have you tried

 Rigidbody2D.AddForce (Vector2.right * someVar);

?

Comment

People who like this

0 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 JPGoal · Mar 12, 2015 at 03:05 PM 0
Share

I type AddForce as given since a lot of the problems with it I saw when researching solutions were because of it. I type it in correctly and I've tried different variables but still nothing.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2D Physics .AddForce 1 Answer

How to find speed in certain direction? 1 Answer

Check for rigidbody presence when in collision with a trigger 2 Answers

Why is rigidbody.addForce calling a Rigidbody2D function? 0 Answers

Add force once when object is created 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