- Home /
Extreme performance impact of Transform.set_localRotation()
I'm having an issue optimizing for performance.
As seen here, i'm having hundreds of calls with all sorts of transformations and raycasts, but the only thing making a significant impact is transforming the local position.
This function is rotating a number of turrets tracking a target.
{
//turns the turret
transform.localRotation = Quaternion.Euler(0, Mathf.LerpAngle(localTransformYRotation,localTransformYRotation + targetAngle.eulerAngles.y, Time.deltaTime * TurretTurnSpeed), 0);
//raises barrel
TurretBarrel.transform.localRotation = Quaternion.Euler(Mathf.LerpAngle(localTransformXRotation, localTransformXRotation + targetAngle.eulerAngles.x, Time.deltaTime * TurretTurnSpeed), 0, 0);
}
Could the information in profiler mean that all the calculations I'm doing in these statements are causing that much trouble or is it actually the act of setting the local position itself?
@stm91 if a GameObject have a Rigidybody is recommended use Rigidybody.rotation to set the rotation of the object.
The parts that i'm moving do not have Rigidbodies.
Just to be sure we talk about the same "static". What tanoshimi ment is the "static checkbox" at the top of the gameobject inspector. Never ever move, rotate or scale objects that has been marked as static. This will have a huge performance hit.
Also if the object has a collider you should add a kinematic rigidbody. Anything that is moved and has a collider should have a rigidbody. Things without rigidbody are considered as "environment" by the physics system and should not move / rotate / scale. If you do it anyways you basically bypass physics and as result you can get weird physics glitches or performance problems.
Your answer
Follow this Question
Related Questions
Slow Motion Physics Lag Spikes 0 Answers
Improve Script Performance Physics 2 Answers
Physic processing takes a lot of time for one rigidbody 1 Answer