Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda