Intro to 3D Game Development

0 of 193 lessons complete (0%)

Scripting Part 1: Moving Objects

Make the Chest Move Up an Exact Amount

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

Right now, we are setting the chest’s world position to a fixed number, so no matter where it starts, it will always move to the same height above the ground. To make sure it moves up from whatever it is, we need to know what its Y value was before we moved it, and add to that.

  1. In the start function, change your line of code to say:

this.entity.worldTransform.position.y = this.entity.worldTransform.position.y + 10

  1. If the chest doesn’t move automatically, click Save on the script and press Play to see it move up. Try changing its starting position, and then pressing Play to see that no matter how high up the chest starts, it always moves up from there.
  2. There is a shorter way to write this! Change your code to say:

this.entity.worldTransform.position.y += 10

  1. Press Play again to make sure that everything is still working the same way.