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).
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.