Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Pawl · Aug 23, 2019 at 06:43 AM · rigidbody2dphysics2dparentjitter

AddForce to RigidBody2D on the same frame as SetParent(null) causes small jitter

I've got a Rigidbody2D sprite that's a child of a rotating circle (the circle does not have a RigidBody2D). When I click the mouse in Update(), I unparent the sprite using SetParent(null) and apply an outward force using AddForce(force, ForceMode2D.Impulse) to the sprite.


When I set the timescale low, I see the sprite jumps a short distance, then pauses for 5-10 frames, and then starts to move smoothly as expected. The short pause is not expected.


When I simply remove the SetParent(null) call, I do not see this short pause. Unfortunately I can't use this as a practical solution as I do need to unparent the sprite.


I've tried calling Physics2D.SyncTransforms() after unparenting, changing the interpolation type for my Rigidbody2D and adjusting Time.fixedTimestep but nothing changes. I also tried waiting a few frames to apply the force after unparenting, but it seems I need to WaitForEndOfFrame() 15-20 frames for this to remove the jitter.


Does anyone know if it's "invalid" to unparent an object the same frame as trying to apply physics?

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
0
Best Answer

Answer by Pawl · Aug 24, 2019 at 05:56 AM

To answer my own question, this seem to simply be a limitation with how Rigidbody2D and transform parenting works.


To work around this, rather than change the parent of my Rigidbody2D object, I create a dummy GameObject and dynamically add it as a child of the rotating circle. Then in Update(), I simply set the position and rotation of my Rigidbody2D object to match the dummy object. This removes the jitter while still allowing me to use the Rigidbody2D for dynamic physics when needed.

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
avatar image
0

Answer by Parokonnyy · Aug 23, 2019 at 10:05 AM

Try to use FixedUpdate instead of Update. For more information: https://learn.unity.com/tutorial/update-and-fixedupdate?projectId=5c8920b4edbc2a113b6bc26a#

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 Pawl · Aug 23, 2019 at 04:27 PM 0
Share

Unfortunately moving AddForce() and/or SetParent(null) to FixedUpdate() didn't make a difference. I think this has to do with parenting but I don't understand why.

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

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

Detect onMouseDown() on children colliders of a rigidbody parent 2 Answers

Platformer2D Player sticks to platform corners 0 Answers

More realistic physics on child collisions 2D 0 Answers

How Do I Make a Rigidbody2d keep its force and move at a consistent speed? 2 Answers

Rigidbody2D.position and Rigidbody2D.MovePosition() 0 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