• 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 /
This question was closed Feb 28, 2014 at 11:24 PM by robertbu for the following reason:

The question is answered, right answer was accepted

avatar image
Question by jimpbblmk · Feb 28, 2014 at 10:23 PM · rigidbodyrigidbody2daddforce

Why is rigidbody.addForce calling a Rigidbody2D function?

I'm trying to write a script that defines the motion of a player-type character in a 3D game by calling rigidbody.addForce, but the console is telling me that there is no Rigidbody2D attached. I'm aware of this, as there's a Rigidbody attached, not a Rigidbody2D, on purpose. I want this to be a 3D game.

 void FixedUpdate () {
     if (Input.GetKey (KeyCode.W)) { //forward
         rigidbody.AddForce(0, 0, 2);
     }
     if (Input.GetKey (KeyCode.S)) { //back
         rigidbody.AddForce(0, 0, -2);
     }
     if (Input.GetKey (KeyCode.A)) { //left
         rigidbody.AddForce(-2, 0, 0);
     }
     if (Input.GetKey (KeyCode.D)) { //right
         rigidbody.AddForce(2, 0, 0);
     }
 }
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 robertbu · Feb 28, 2014 at 10:42 PM 1
Share

Nothing here should cause that problem. Any references to rigidbody2d in the script anywhere? Any other components attached to the game object that might reference rigidbody2d? What line in Monodevelop is highlighted if you double click on the error.

avatar image jimpbblmk · Feb 28, 2014 at 11:05 PM 0
Share

Ugh. Found the problem. I had left a different script in the Assets folder that was causing the error. Sorry about the confusion.

[request to close thread]

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Add force once when object is created 1 Answer

Rigidbody.AddForce not being detected 2 Answers

how to make "addForce" only affect one of several connected objects (with hinge points) 0 Answers

How to find speed in certain direction? 1 Answer

Unity 2D Physics .AddForce 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