Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 2: Making Code Respond to Players

Challenge: Rotate the Chest Lid Over Time

You don’t have access to this lesson
Please register or sign in to access the course content.

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 the elapsedTime by the animationTime.
  • 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 the startingRotation.
  • Set the entity’s local rotation to that value.

And make sure you increment elapsedTime by the game frame delta time.