hi i have just started using unity a few weeks ago.
i have done the tutorials on spaceshooter and roll the ball tutorial.
when we rotate the cube in the ball game,we do it in the update function.but when we are rotating the asteroid in the spaceshooter, why we can just rotate it in the start function??
this is how we make the asteroid rotate in spaceshooter game:
using UnityEngine;
public class AsteroidMovement : MonoBehaviour {
private Rigidbody rb;
public float tumble;
// Use this for initialization
void Start()
{
rb = GetComponent();
rb.angularVelocity = Random.insideUnitSphere * tumble;
}
}
this is how we make the cube rotate in the ball game :
Please look at this page for how to post code nicely on the forums, for future reference: Using code tags properly
It’s good that you began with some tutorials. That’s a good start.
The reason they are a bit different, is the first piece of code is setting the angular velocity which will continue during play. It can be modified by other forces, or angular drag, though. This is using the physics system, and works with rigidbodies.
The second code example is modifying the rotation a little at a time, each frame and using the transform (rather than the rigidbody). It’s not using the physics system.