• 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 ticofa · May 16, 2015 at 03:52 AM · rigidbody2d gameaddforcetop downforcemode

Rigidbody AddForce Forcemode.Impulse not working 2D game...

Every time i try to use addforce with impulse as the forcemode, the object will not jump, but if i remove the impulse forcemode it will jump, what i am doing wrong :S?

this is my script...

 void Update()
     {
         if (Input.GetKeyDown(KeyCode.W)) {
             Vector3 _jump = new Vector3(0,10,0);
                 this.gameObject.rigidbody.AddForce(_jump, ForceMode.Impulse);
         }            
     }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by IsaiahKelly · May 16, 2015 at 06:13 AM

Impossible to know exactly without more info, since many things could be effecting this (gravity, drag, mass, other forces, etc.) However, if you're using a Rigidbody2D then your code should probably be:

        gameObject.rigidbody2D.AddForce (Vector2, ForceMode.Impulse)
      

You should also be caching the Rigidbody reference in OnStart for best performance.

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 ticofa · May 17, 2015 at 04:06 PM 0
Share

Holy S"#$ i'm an idiot xD Of course im using a 2D Rigidbody x'DD If im making a 2D game (2D project setting) it's a rigibody2D, now it's working :D thank youuuuuu :D!

avatar image
2

Answer by luislodosm · Aug 10, 2016 at 07:12 AM

Use ForceMode2D instead of ForceMode:

 gameObject.rigidbody2D.AddForce (Vector2, ForceMode2D.Impulse);
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

19 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

Related Questions

Difference and uses of rigidbody force modes ? 2 Answers

Confusion with AddForce with ForceMode.Acceleration 1 Answer

Addforce - bug with jump 2 Answers

Erratic Physics behaviour while testing in 2 computers 0 Answers

Rigidbody starts moving without an applied force 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