# Spotlight can't set target correctly

**URL:** <https://discourse.threejs.org/t/spotlight-cant-set-target-correctly/3674>\
**Category:** Questions\
**Tags:** lights\
**Created:** [August 4, 2018, 10:03am UTC](https://discourse.threejs.org/t/spotlight-cant-set-target-correctly/3674 "2018-08-04T10:03:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![taremimi\_7](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/taremimi_7/32/2345_2.png) [@taremimi\_7](https://discourse.threejs.org/u/taremimi_7)\
**Post date:** [August 4, 2018, 10:03am UTC](https://discourse.threejs.org/t/spotlight-cant-set-target-correctly/3674/1 "2018-08-04T10:03:41Z")

</div>

Hi, I’m trying to set up the spotlights, but target always directs to (0,0,0).  
I’ve tried

- spotlight.target.position.set(x,y,z);
- spotLight.target = object;
- spotLight.lookAt( object.position ); ← this direct to weired point(not expected direction)

and also I’ve tried

```auto
scene.add( spotLight );
scene.add( spotLight.target );

```

but it didn’t work…  
I would appreciate if anyone had any solution.  
Thanks!

---

<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:** [August 4, 2018, 2:18pm UTC](https://discourse.threejs.org/t/spotlight-cant-set-target-correctly/3674/2 "2018-08-04T14:18:53Z")

</div>

Try it with this basic template:

[https://jsfiddle.net/f2Lommf5/10847/](https://jsfiddle.net/f2Lommf5/10847/)

Also see:

> <https://stackoverflow.com/questions/32203806/three-js-spotlight-orientation-direction-issue>

---

<div class="post-metadata">

**Author:** ![taremimi\_7](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/taremimi_7/32/2345_2.png) [@taremimi\_7](https://discourse.threejs.org/u/taremimi_7)\
**Post date:** [August 5, 2018, 10:14pm UTC](https://discourse.threejs.org/t/spotlight-cant-set-target-correctly/3674/3 "2018-08-05T22:14:53Z")

</div>

It works!!! Thank you sooooo much Mugen87 !!!

---

<div class="post-metadata">

**Author:** ![jamie.games](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jamie.games/32/21956_2.png) [@jamie.games](https://discourse.threejs.org/u/jamie.games)\
**Post date:** [October 31, 2021, 7:37am UTC](https://discourse.threejs.org/t/spotlight-cant-set-target-correctly/3674/4 "2021-10-31T07:37:23Z")

</div>

If anyone wants to see the spotlight animate with the spotlight helper, you can make the following changes to @Mugen87 's jsfiddle.

```javascript
// Add this at the end to declare `spotLightHelper`
let camera, scene, renderer, clock, spotLight, spotLightHelper;

init();
animate();

...

	scene.add( spotLight.target ); // add target to the scene

// Add this to add a SpotLightHelper
	spotLightHelper = new THREE.SpotLightHelper(spotLight, 0XFF00FF)

	scene.add(spotLightHelper);
...
	spotLight.target.position.z = Math.cos( time );
// Add this in animate() to make sure it animates.
    if (spotLightHelper) spotLightHelper.update();
...

```
