Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
0
Question by hirenkacha · Dec 06, 2013 at 10:18 AM · rigidbody2daddforcejerky

rigidbody2D.AddForce() to a character gives jerky motion

Hi all,

I am adding the force to a simple sprite having rigidbody2d component. Sprite mass is 1, gravity scale is 1. I don't have too much of code and no such BG's just a simple ground and a character in the scene. FPS I am getting on PC 55-60 and on mobile 45-50. Still, while jumping, I found the character too jerky when in motion. I tried with target FPS, but didn't work. Simple code I am using is

 void FixedUpdate () 
     {
         if(Input.GetKeyDown(KeyCode.Mouse0))
             {
                 rigidbody2D.AddForce(Vector2.up*400f);
             }
     }
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
3
Best Answer

Answer by meta87 · Dec 06, 2013 at 10:41 PM

Try turning on interpolation in the Rigidbody2D component. I'm having the same issue. Unfortunately interpolation is behaving very strangely for me, but it might work in your case!

Comment
Add comment · 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 hirenkacha · Dec 07, 2013 at 04:40 AM 0
Share

Working now.. Interpolation did the trick..

avatar image NithinPiratez hirenkacha · Apr 10, 2017 at 04:56 PM 0
Share

Yes, it works!

avatar image
0

Answer by Everspace · Dec 06, 2013 at 11:23 PM

Try moving the code to Update(). Because it's in fixed update, it doesn't get applied every frame so it looks jerky/feels wrong.

Comment
Add comment · Show 5 · 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 meta87 · Dec 07, 2013 at 12:35 AM 1
Share

Physics forces should never be applied in Update

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.FixedUpdate.html

avatar image Everspace · Dec 07, 2013 at 04:40 AM 0
Share

Remember that never is different than should. When dealing with the player, you are already gating by the input, and input should be dealt with in update. The player could bog down if physics are going wacky. The recommendation is just so you don't end up with something super crazy by adding force every frame.

avatar image hirenkacha · Dec 07, 2013 at 05:08 AM 0
Share

I have already tried both the methods but didn't work..

avatar image meta87 · Dec 07, 2013 at 05:49 AM 0
Share

If you look at the 2d Tower Defense demo created by Unity, Everspace, (PlayerControl.cs specifically) You will see that Input and all physics are handled in FixedUpdate. They also have Interpolation turned on and the hero gameobject is very smooth.

Sorry to hear it's still not working hirenkacha. I will post if I come up with any answers.

Show more comments

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

21 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

Related Questions

rigidbody2d.addforce for is not working for the x axis 0 Answers

add force on topdown bullet 1 Answer

Rigidbody2d addforce is weaker at a higher y position. 2 Answers

How to find speed in certain direction? 1 Answer

Jumping is slightly faster than running due to friction 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