- Home /
Question by
TheCorypheus · Feb 25 at 11:47 AM ·
performancetransform.positiondouble-float
Performance issue with code
Hi, I am trying to rotate an object around a center and wrote the following code for this:
float angle;
angle = Vector3.SignedAngle(from, to, axis);
void Update(){
angle += Time.deltaTime * RotationSpeed;
Vector3 offset = new Vector3(Mathf.Cos(angle) * radius, Mathf.Sin(angle) * radius, 0f);
transform.position = offset + center;
}
Since the object is very far from the center however, I run into floating point precision problems, so I decided to let angle be a double instead of a float and wrote the following code:
double angle;
angle = CustomSignedAngle(from, to , axis);
void Update(){
angle += Time.deltaTime * RotationSpeed;
Vector3 offset = new Vector3((float) Math.Cos(angle) * radius,
(float) Math.Sin(angle) * radius, 0f);
transform.position = offset + center;
}
With this implementation I don't have floating point precision issues anymore, but the line: transform.position = offset + center; makes the framerate drop to 2, which I can't understand, since offset is pretty much identical in both cases. Does someone know why this happens?
Comment