- Home /
Accurate placed object's transform messes up on game start
I have a cube:
alt text
That is placed over another cube:
alt text
In the scene they are placed like this:
alt text
As the second cube is kinematic it isn't affected by gravity and acts as ground layer on which the cube lays. If i start the game the cubes transform and rotation messes up like this:
alt text
This shouldn't be that big of a problem but as the cube is affected by forces many times its direction changes massively! The only reason for the occurrence of this problem is Unity's use of floating point variables for the position and rotation. If this really is the problem is there any way to solve this?
Thanks!
Answer by Xarbrough · Jun 22, 2015 at 01:01 AM
Why exactly do you think this is a problem? Your cube uses Physics, so when the game starts, it falls down a tiny amount and then should come to rest.
The position and rotation values are not at all "messed up" they are just showing that they are, very tiny values much smaller than 0. Shouldn't cause any problems. It's just that in the Physics world, nothing will land exactly at whole increments.
But the cube shouldn't fall. It is exactly placed on the plane with no room to fall. And it as well causes problems: I let the cube roll with: rb.AddForceAtPosition(new Vector3(150f, 0f, 0f), Vector3.up);
it should roll in a perfect line but after 20 rotations its position.y value (which should be 0 all the time because i only apply force in x direction) is at -0.7841578 due to the $$anonymous$$imal rotation at the beginning.
Are you sure its value is at -0.78 and not something much smaller liker -0.784157e-05 or something? I don't think it slowly passes through the other collider. But again, in Physics there is no way to move from exactly point a to exactly point b. There is too much going on...Physics materials friction, colliders and gravity fighting. And if you're moving a cube and slide it on the ground there will always be some jitter because of the sharp collider edges. A perfect sphere collider will roll much softer. If you need perfect results, don't use AddForce, use Translate and kinematic rbs.
The value is definitely -0.78 the cube in the scene (on start it is centered) looks like this after a few turns:
The thing is that it would be really hard to work with position and rotation ins$$anonymous$$d of physics because the movement wont look that nice so i don't know any other way. So is there really no way to get around this rotation fluctuations?
Your answer
Follow this Question
Related Questions
Floating-point errors while assigning transforms 1 Answer
Player not facing the mouse correctly 1 Answer
Change object position on trigger enter 3 Answers
How can I modify this rotation code to change how far the object rotates? 0 Answers
postion scale and rotation greyed out and not working 1 Answer