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.
- In the start function, change your line of code to say:
this.entity.worldTransform.position.y = this.entity.worldTransform.position.y + 10
- 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.
- There is a shorter way to write this! Change your code to say:
this.entity.worldTransform.position.y += 10
- Press Play again to make sure that everything is still working the same way.