Var Rotation

I have figured out a make shift way to update the rotation of a transform with if statements comparing the variable float. but im sure there is a better way to do this. If anyone has any examples. That would Rip.

var mmm = 0.0;
//My example of what i have now
function Update () {
mmm += 0.1;
if ((mmm >=4)  (mmm<=4.5)) {
transform.Rotate(Vector3.right/5);
}
}

This works like i want, but i would have to write like 200 if’s lol
The idea is to control the rotation from a static var so that my time of day will update the rotation of the moon. :smile:
Also what would be the best way to have a moon texture far away (ie)like a skybox or sun flare without expanding my clipping?

Imho your script would just make the moon spin around it’s own axis, but from what I understand you want the moon to “wander” across the sky? I guess this would be accomplished by rotating the moon around the earth’s core/some other object. Here’s a script that can be used for both:

var rotationMask = Vector3(0, 1, 0); //which axes to rotate around
var rotationSpeed = 5.0; //degrees per second
var rotateAroundObject: Transform;
//if <rotateAroundObject> is != null then use <transform.RotateAround>, else <transform.Rotate>

function FixedUpdate()
{
	if (rotateAroundObject) //is set -> orbit <rotateAroundObject>:
	{
		transform.RotateAround(rotateAroundObject.transform.position, 
				rotationMask, rotationSpeed * Time.deltaTime);
	}
	else //not set -> rotate around own axis/axes:
	{
		transform.Rotate(Vector3(
				rotationMask.x * rotationSpeed * Time.deltaTime,
				rotationMask.y * rotationSpeed * Time.deltaTime,
				rotationMask.z * rotationSpeed * Time.deltaTime));
	}
}

If you assign an object to rotateAroundObject in the inspector, your moon should rotate around it, otherwise it will spin around it’s own axis.

Hope this is what you’re looking for.

Thanks for the example, This should work just fine :smile: