Hi, I’m making a 3d maze in first person, and I wanted to make the maze rotate 180 degrees every x minutes. I understand loops and timing, but I can’t seen to find a way to rotate an object a particular degree at a time. All I find is rotation and a certain speed.
There are many ways to move a value between 2 points smoothly (I’m sure you can figure out the rest)
As you have not provided any code to build upon, I will make a couple of assumptions.
/*
One of the "cleanest" methods you could use, is to
take advantage of yield and have everything packaged
in one function
*/
//Turn speed is measured in degrees per second
var turnSpeed:float;
function StartTurn(angle:float) {
while (transform.eulerAngles.y < angle) {
transform.eulerAngles.y += turnSpeed*Time.deltaTime;
yield;
}
transform.eulerAngles.y = angle;
}
/*
You could also use Lerp (preferable LerpAngle)
To accomplish the same thing.
This might take a little more memory,
however it is more optimised
*/
//Here turn speed is normalised, so 180 degrees per second
var turnSpeed:float;
private var turnTo:float = 0;
private var turnFrom:float = 0;
private var turnWeight:float = 1;
function StartTurn() {
turnTo = transform.eulerAngles.y + 180;
turnFrom = transform.eulerAngles.y;
turnWeight = 0;
}
function Update() {
turnWeight += turnSpeed*Time.deltaTime;
//Use lerp to more smoothly between the angles
transform.eulerAngles.y = Mathf.LerpAngle(turnFrom, turnTo, turnWeight);
}
Those are the two methods I could come up with off the top of my head. Neither of them are tested, so don’t hesitate to ask about errors