# Moving a single object from a scene of multiple objects using keyboard controls

**URL:** <https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288>\
**Category:** Questions\
**Tags:** interaction\
**Created:** [March 4, 2020, 1:31pm UTC](https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288 "2020-03-04T13:31:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Athira\_Narayan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/athira_narayan/32/9201_2.png) [@Athira\_Narayan](https://discourse.threejs.org/u/Athira_Narayan)\
**Post date:** [March 4, 2020, 1:31pm UTC](https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288/1 "2020-03-04T13:31:21Z")

</div>

I have added 3 objects to my scene: a cube, a cuboid and a pyramid(cuboid is child of cube,but pyramid is not.). I want to move the pyramid on clicking the keyboard arrows.But all the 3 objects are moving,instead of pyramid alone. What could be the reason?  
code snippet:

```
    pyramid.name='fov';
    scene.add(pyramid);
    /*some codes in between*/
    function movement(e){

          var distance = 0.15;

          var fov = scene.getObjectByName('fov');

          if(e.keyCode =='37'){

              fov.position.x += distance;

              }

          else if (e.keyCode == '38'){

              fov.position.z += distance;

          }

          else if (e.keyCode == '39'){

            fov.position.x += distance;

          }

          else if (e.keyCode == '40'){

            fov.position.z += distance;

          }

```

 ![Screenshot (38)](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/b/b9ee1fbf98b40837faed817bbcc7d50217852c98.png)

---

<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:** [March 4, 2020, 2:26pm UTC](https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288/2 "2020-03-04T14:26:06Z")

</div>

Please demonstrate your issue with a live example: [https://jsfiddle.net/f2Lommf5/](https://jsfiddle.net/f2Lommf5/)

It’s currently not possible to see from your code and screenshot what’s going wrong.

---

<div class="post-metadata">

**Author:** ![Athira\_Narayan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/athira_narayan/32/9201_2.png) [@Athira\_Narayan](https://discourse.threejs.org/u/Athira_Narayan)\
**Post date:** [March 5, 2020, 5:07am UTC](https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288/3 "2020-03-05T05:07:18Z")

</div>

Here is the link to live example: [https://jsfiddle.net/Athira\_Narayan/w3ax6dku/10/](https://jsfiddle.net/Athira_Narayan/w3ax6dku/10/)  
I want to move the pyramid along the top horizontal edge of the red cube.

---

<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:** [March 5, 2020, 8:50am UTC](https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288/4 "2020-03-05T08:50:16Z")

</div>

Updated fiddle: [https://jsfiddle.net/pgf0sdqn/](https://jsfiddle.net/pgf0sdqn/)

- You have not added your event listener to the `keydown` event. So this line was missing:

```auto
document.addEventListener( 'keydown', onKeyDown );

```

- You also have to disable the key input for `OrbitControls` like so:

```auto
controls.enableKeys = false;

```

Otherwise you translate the camera when you actually only want to translate the pyramid.

---

<div class="post-metadata">

**Author:** ![Athira\_Narayan](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/athira_narayan/32/9201_2.png) [@Athira\_Narayan](https://discourse.threejs.org/u/Athira_Narayan)\
**Post date:** [March 5, 2020, 10:47am UTC](https://discourse.threejs.org/t/moving-a-single-object-from-a-scene-of-multiple-objects-using-keyboard-controls/13288/5 "2020-03-05T10:47:48Z")

</div>

Okay. Noted that. Thankyou Mugen 🙂
