Three-fiber get spotlight with a new position to point straight down

In three-fiber, I have a spotlight, but it is "pointing" at {[0,0,0]}. I tried adjusting the target and the lookAt properties to {[0,0,0]}

<spotLight position={[0, 20, -20]} intensity={1.5} color="#fff" penumbra={0.5} castShadow={false} /> 

TypeError: Cannot read properties of undefined (reading 'elements')

As soon as I take away the target, it works, but its still pointing at [0,0,0].

1 Answer

The target of SpotLight must be an object added to the scene.

React-three-fiber implementation:

const spotlight = useMemo(() => new SpotLight('#fff'), []); <group> <primitive object={spotlight} position={[0, 20, -20]} intensity={1.5} penumbra={0.5} /> <primitive object={spotlight.target} position={[0, 0, 0]} /> </group> 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like