- Home /
Question by
ayeitsamresh · Sep 19, 2020 at 04:35 AM ·
randomrotate object
How to get a game object to rotate (change direction from clockwise to anticlockwise) randomly around a circle.
{ public float maxRotationSpeed = 50f; public float maxFrequency = 3f; public float speed; public GameObject earth; float timeLeft, rotX, rotY;
// Update is called once per frame
void Update()
{
timeLeft -= Time.deltaTime;
if (timeLeft <= 0)
{
rotX = Random.Range(-maxRotationSpeed, maxRotationSpeed);
rotY = Random.Range(-maxRotationSpeed, maxRotationSpeed);
timeLeft = Random.Range(0, maxFrequency);
}
speed = -90;
transform.RotateAround(earth.transform.position, Vector3.forward, Random.Range(0.1f,1f) * speed * Time.deltaTime);
}
this is what i have so far and its rotating clockwise but not randomly changing directions
Comment
Your answer
Follow this Question
Related Questions
Select from an array based on values 1 Answer
Call a function multiple times 2 Answers
Random.range multiple instantiations without repetition 1 Answer
How do I seed the random number generator myself and still get pseudorandom values? 2 Answers
Function action applies to every object that have script with that function on it. Help please 1 Answer