- Home /
Infinite Moving/Rotating Question
I have objects in my game that I need to move and rotate forever. I was wondering what the most efficient way of doing this was. Here are the two that I've tried so far:
void Start()
{
_tran = this.transform;
}
void Update()
{
_tran.position -= Vector3.up * _speed*Time.deltaTime;
_tran.Rotate(_rotation* Time.deltaTime, Space.World);
}
//Or
void FixedUpdate()
{
_tran.Rotate(0, 0, _rot, 0);
_tran.Translate(0, _speed, 0, 0);
}
When using the profiler, it appeared that the Update() method was more efficient, I could be wrong. The object also has a Rigidbody2D and a CircleCollider2D, if that matters.
Thanks!
Comment
Answer by Dreamora · Jun 22, 2014 at 10:12 PM
Both should even out on their cost, but given that you have a rigidbody present, you optimally would use the rigidbodys position property or the physic functionality in FixedUpdate to ensure the physics update correctly. Changing the transforms position in Update has a very high chance of actually breaking the physical behavior.