- Home /
Objects get small offset after Instantiate
After Instantiate i rotate the object with integer amount(90 or 180 ...). But when viewed from editor it has a rotation of 90.000001. This is a problem because I'm trying to trace the object with boxes, but this small rotation causes an extra row of boxes to appear and this breaks rest of the logic that depend on the accuracy of the box positions.
void MatchExits(GameObject exit1, GameObject exit2)
{
GameObject newPart = exit2.transform.parent.gameObject;
Vector3 forwardToMach = -exit1.transform.forward;
int correctiveRotation = (int)(Azimuth(forwardToMach) - Azimuth(exit2.transform.forward));
newPart.transform.RotateAround(exit2.transform.position, Vector3.up, correctiveRotation);
// Debug.Log(Mathf.Round(correctiveRotation));
Vector3 correctiveTranslation = exit1.transform.position - exit2.transform.position;
newPart.transform.position += correctiveTranslation;
}
Answer by TonyLi · Jun 08, 2017 at 05:57 PM
That's floating point for you. You'll need to assign values without doing any floating point math on them, or work within tolerances instead of exact values.
Your answer
Follow this Question
Related Questions
FPS, character arm movement 0 Answers
Flip over an object (smooth transition) 3 Answers
Cam giving problem on rotation and pan 0 Answers
Problem with normal snapping and rotations. 1 Answer
Instantiate Bullet Hole position and rotation, Vector3 issues 1 Answer