Now that you have calculated the amount that the rotation needs to change, write the code to make the chest rotate slowly over time. This should look a lot like the animation code you wrote for the Chest-Bottom, so refer back to ChestScript to get hints on how to do this.
In the tick
function:
- Make a variable with
let
for what percent finished the rotation is and then calculate how far along your rotation should be by dividing theelapsedTime
by theanimationTime
. - Use an if-statement to only execute the rest of the code if that percentage is less than 1 (the same thing as 100%).
- Multiply that percentage by the
rotationChange
(in your correct axis) and add it to thestartingRotation
. - Set the entity’s local rotation to that value.
And make sure you increment elapsedTime
by the game frame delta time.