Starting a game object with a random direction.

What I wanted was to have an object Start (eventually instantiated or pooled) with a random Y direction. I have this working properly in my scene but I feel like I strong-armed this solution multiplying the Deg2Rad by 10k.
Is that going to bite me in the ass later on?

Well… I just realized my own mistake. eulerAngles does all the dirty work.

    public float deg;
    public float speed;
    public float startRot;

    private float rad;
    private float yRotation;

    void Awake(){
        RotRandom ();
    }

    void RotRandom(){
        startRot = Random.Range (0, 360);
    }

    void TurningRad() {
//        yRotation = startRot * Mathf.Deg2Rad * 10000;
        yRotation = startRot;

        transform.eulerAngles = new Vector3 (0, yRotation, 0);
    }

    void Update(){
        TurningRad ();
        transform.Translate (Vector3.forward * speed * Time.deltaTime);
    }

eulerAngles is an acceptable solution in this particular situation, but be careful using it elsewhere - especially getting the value out of it, in which case Euler angles are just plain useless.

1 Like