Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
One direction SpotLight with PointerLockControls in Threejs

I'm trying to attach a directional flashlight to the camera (controls object) so the beam is always where center of the screen is aiming at. This is my code:

controls = new PointerLockControls( camera, document.body );
var flashlight = new THREE.SpotLight(0xffffff, 7, 50, 0.8*Math.PI);
controls.getObject().add(flashlight);
controls.getObject().add(flashlight.target);

but the result is the light around camera, not a straight beam. (see pic below)

Flashlight beam

so how can I achieve a directional beam?

//edit, added Group.

controls = new PointerLockControls( camera, document.body );
var flashlight = new THREE.SpotLight(0xffffff, 7, 50, 0.8*Math.PI);
// camera.add(flashlight);
// camera.add(flashlight.target);
const group = new THREE.Group();
group.add(camera);
group.add(flashlight);  
scene.add(group);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use a THREE.Group to group objects together

const group = new THREE.Group();
group.add(camera);
group.add(flashlight);

// Finally, we add the group to our controls
controls = new PointerLockControls( group, document.body );

Then you can add the group to your scene, and control the group as a whole. The camera and flashlight will rotate and translate together.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!