# \[solved\] How to animate the position of a gltf model

**URL:** <https://discourse.threejs.org/t/solved-how-to-animate-the-position-of-a-gltf-model/4832>\
**Category:** Questions\
**Tags:** animation\
**Created:** [November 7, 2018, 1:50pm UTC](https://discourse.threejs.org/t/solved-how-to-animate-the-position-of-a-gltf-model/4832 "2018-11-07T13:50:56Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [November 7, 2018, 3:05pm UTC](https://discourse.threejs.org/t/solved-how-to-animate-the-position-of-a-gltf-model/4832/2 "2018-11-07T15:05:36Z")

</div>

If you comment in your animation code, you get the following error:

> pen.js:96 Uncaught ReferenceError: gltf is not defined

The problem is that you try to access a variable which is out of scope. `gltf` only exists in the `onLoad()` callback of `GLTFLoader.load()`. I have fixed your code my defining a global variable `model` and assigning `gltf.scene` to it. I use this variable in the `animate()` function like so:

```js
if ( model && ( model.position.x >= targetPositionX5 ) ) {

    model.position.x -= 0.0032;

}

```

Updated codepen: [https://codepen.io/anon/pen/mQVeKQ](https://codepen.io/anon/pen/mQVeKQ)

---

_[View the full topic](https://discourse.threejs.org/t/solved-how-to-animate-the-position-of-a-gltf-model/4832)._
