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 TomasRiker · Jun 07, 2019 at 03:18 PM · physicsrigidbodyrigidbody physics

Can't set position of Rigidbody precisely

I'm trying to capture and restore the state of a Rigidbody with a couple of colliders for the purpose of doing rollback in a multiplayer game. Unfortunately, this seems impossible.

Even something as simple as this won't work:

 //
 var position = rigidbody.position;
 rigidbody.position = position;
 Debug.Log(rigidbody.position.Equals(position)); // Will mostly log "False"!
 //

In other words: Asking the Rigidbody for its position and then setting exactly that position will result in a (slightly) different position. That makes rolling back impossible :-(

It seems like it only happens when there are multiple colliders attached to the Rigidbody.

Any ideas what might cause this or how it can be fixed?

Comment
Add comment · Show 10
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 TreyH · Jun 07, 2019 at 03:22 PM -1
Share

You should avoid using .Equals, use == ins$$anonymous$$d per the documentation:

https://docs.unity3d.com/ScriptReference/Vector3.Equals.html

avatar image TomasRiker · Jun 07, 2019 at 03:33 PM -1
Share

@TreyH No, Equals is correct here because I want to make sure that the values are exactly the same, not just within some tolerance. Even slight differences quickly lead to a completely different simulation result.

avatar image TreyH TomasRiker · Jun 07, 2019 at 03:38 PM -1
Share

Floating point equality comparison isn't guaranteed, that's just part of life.

If you need control over that tolerance and don't trust Unity's, then implement it yourself, but you can't get around machine epsilon or floating point inequality.

avatar image TomasRiker · Jun 07, 2019 at 03:56 PM 0
Share

@TreyH I am well aware of floating point intricacies, but I don't think this is the problem here. When you assign a value to itself you can expect to get that value back. Seems like when you set a Rigidbody's position, there's a lot going on behind the scenes ...

avatar image TreyH TomasRiker · Jun 07, 2019 at 05:07 PM 0
Share

I don't know much about Unity's networking, is there some syncing issue maybe? In an offline editor, even .Equals is only true for me when doing self-assignment.

avatar image TomasRiker TreyH · Jun 07, 2019 at 05:26 PM 0
Share

No networking is needed to reproduce the problem. All I want to do is to fully restore a Rigidbody's state including position, rotation, velocity and angular velocity. I was assu$$anonymous$$g that if I remember these properties, I can restore them later on to rewind the simulation. If it was just a simple assignment, that would work. But Unity does something behind the scenes, some calculations, and then precision is lost ... Then playing back the simulation will lead to a different result.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

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

Rotate child object under RigidBody parent 0 Answers

Rigidbody climbing stairs 2 Answers

Move rigidbody to position and still have forces act on it 0 Answers

VR Sword Physics, how to add force or velocity to the sword for impact when it hits an object 1 Answer

Rigidbody NavMeshAgent Causing Crazy Collisions with Player. 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