- Home /
Stack of RigidBody2D, Freeze X and Z, Odd Behavior
I have a prefab I call "Tile", which has Sprite, BoxCollider2D, and RigidBody2D. I also have another object I call "Base" which has Sprite and BoxCollider2D.
There is nothing special about Sprite or BoxCollider2D, just the defaults with my image.
The RigidBody2D on Tile has Freeze X position and Freeze Z rotation.
I have 5 tiles stacked vertically on top of each other (in a column), with Base under them to catch them. The 5 Tiles and 1 Base are also in an empty Game Object called Board, for grouping.
The idea is that the 5 fall on top of each other, only in the Y direction, and pile up on Base and each other.
This mostly works as expected except for one thing: one of the Tiles (which is largely random) kind of gets sucked to the center of Board (if Board has an X of 1.6, the Tile gets an X of -1.6, etc). Even if I try to move it while the game is running (via the Scene tab), it just gets pulled right back there. If any other Tiles touch it, they also get vacuumed to this spot.
There are no other scripts or anything that could be interfering. I don't even have any scripts that use anything related to the physics in the project yet. The closest I have is using Transform to simply get children objects for things like setting the text of a Text object.
Any ideas?
Quick update: Interestingly, if I set them to Is Kinematic, the one still gets pulled to the middle. Also, if I remove Freeze X, one does not get pulled to the middle.
Update 2: It appears to only do it sometimes. It does it more often than not, but when if I sit there and turn the play test on and off a few times, sometimes it won't do it. I thought overlapping pieces may play a part, but even when I space them substantially apart, they still may do it. I'm wondering if this isn't just a Unity bug.
Answer by NordSpirit · Dec 22, 2015 at 05:24 PM
Hello, I stack with a same things, if you checked freeze position x, sometimes it pull to the center of the scene. I think this is bug or something. So I Just make script that take x.position of my game object on x axis, and place it on FixedUpdate.
Vector3 ert = this.transform.position; ert.z = 0.0f; ert.x = 0.0f; transform.position = ert
P.S. I know that is not best way to solve this problem, but it's work. @samanime
Your answer
Follow this Question
Related Questions
increasing knockback of a rigidbody as received damage increases (like super smash) 1 Answer
How to make physics relative to moving parent 1 Answer
Rigidbody2D: Follow other Rigidbody2D strictly 1 Answer
Inconsistent gravity/random forces/solver problem? (forum crosspost) 0 Answers
Recalculating collisions after Physics2D.IgnoreLayerCollision()? 1 Answer