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 yoohee2018 · Jul 30, 2018 at 09:06 AM · transform.positionparent-child

One child object move differently as 0.0001f when moving parent

Hello. I'm on developing game in 2D.


A parent gameobject has 3 children object.

  • child 1's localposition : (-25.6, 0, 0)

  • child 2's localposition : (0,0,0)

  • child 3's localposition : (25.6, 0, 0)

Children have SpriteRenderer and nothing else.

(all objects are not rigidbody, and don't have any colliders.)

I want to move 3 children object in same speed, so I translate parent object's transform at LateUpdate.

(Using LateUpdate because the parent object must follow camera move and camera should follow other game object (e.g. Player) ).

The move is only horizontal. (Only X move.)


[Here's problem]

  • Occasionally one of the children moves 0.0001f point more or less on a frame. (randomly)

  • And the wrongly moved child get back accurate position at next frame

  • So, while playing, black line (background color) appears between the children sprites and disappears soon (disappears at next frame).


alt text


My camear is Orthograpic and size 7.2.

The Sprite of children are same size of 2560x2560 pixel. (Pixels per unit is 100)

this is LateUpdate code, and it's added to parent gameobject.


 public void MoveParallaxing(){
 
         parallax = Mathf.Floor((cam.position.x - previousCamsPos.x) * parallaxScale * 10000) / 10000;
 
         if (Mathf.Abs(parallax) > 0.01f){
             
             float backgroundTargetPosX = Mathf.Max(transform.position.x + parallax, minX);
             Vector3 backgroundTargetPos = new Vector3(backgroundTargetPosX, transform.position.y, transform.position.z);
             transform.position = backgroundTargetPos;
 
         }
         previousCamsPos = cam.position;
     }


What am i missing? Please give me some clue. Thank you in advance.


스크린샷-2018-07-30-오후-53006.png (270.3 kB)
스크린샷-2018-07-30-오후-60410.png (152.2 kB)
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

1 Reply

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

Answer by Bunny83 · Jul 30, 2018 at 09:44 AM

That's just normal floating point precision. Keep in mind that the actual position of your sprites are defined in local space, so they don't move at all. The worldspace position of an object that has a parent is always calculated based on the parents position, rotation, scale and the object's local position. The greater a floating point value gets before the binary point / decimal point, the less precision you have behind the binary / decimal point. I've posted a table over here. So if your parent is at (0,0,0) the worldspace position of your objects are "+- 25.6" (25 requires 5 bits before the binary point). Though if you have the parent to "300" the worldspace position would be 325.6 which requires 9 bits before the binary point. So you have 3 bits less behind the binary point. Finally keep in mind that numbers are stored in binary not decimal. Not every decimal number can be precisely represented. Just like you can't represent (1 / 3) in decimal precisely you can't represent different numbers precisely in binary.


I recommend to watch this computerphile video about floating point numbers

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 yoohee2018 · Jul 30, 2018 at 02:53 PM 0
Share

Thanks for your replay. It was helpful. but I cannot find the solution. i'm using this code for horizontal background image. maybe i have to find other ways. Thank you!

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

88 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

Related Questions

need to predict child position from a rotating parent (no gravity/physics) 1 Answer

Unity Object Aligment in Different Resolutions and Scales 0 Answers

How to transform position of object A to object C (C is a child of B object) 1 Answer

How Do I Give Two Objects the Same Transform? 1 Answer

How to transform children of an object? 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