I’m looking if there is a way to revolve it around the pinpoint continuously in reactjs(not in vanilla cause I know this but I don’t know how can I make it work to reactjs) ?
Like this certain image
I already have a ready code about it,
So basically they are on each edge of the tower.
let pos = [
{ x: -35, y: 10, z: 35 },
{ x: 35, y: 10, z: 35 },
{ x: -35, y: 10, z: -35 },
{ x: 35, y: 10, z: -35 }
].map(pos => [
pos.x,
pos.y,
pos.z
]);
const [positions, setPositions] = useState(pos);
useFrame(() => {
/// this is will the changes of position of spotLight will happen.
})
/// And the display is here
{positions.map((elem,i) => (
<spotLight
color={0xffffff}
intensity={1.5}
angle={0.6}
penumbra={0.5}
castShadow
position={elem}
shadow-bias={-0.0001}
key={i}
>
</spotLight>
))}
And I have a similar projects before but it is following the camera position but with a 2-meter distance away at the camera.
useFrame((state) => {
cameraRef.current = camera;
if (cameraRef.current) {
let pos = [
{ x: -2, y: 0, z: 0 },
{ x: 2, y: 0, z: 0 },
{ x: 0, y: 2, z: 0 },
{ x: 0, y: -2, z: 0 },
{ x: 0, y: 0, z: 2 },
{ x: 0, y: 0, z: -2 }
].map(pos => [
(cameraRef.current.position.x - 5) + pos.x,
(cameraRef.current.position.y - 2) + pos.y,
(cameraRef.current.position.z) + pos.z
]);
setPositions(pos);
}
});
but I want it to circulate around the pinpoint without any camera needed. Remember only at one pin point the spotLight is looking at.
UPDATE:
I don’t want this one code
useFrame(state => {
angle += 0.01; // increase the angle by a small amount each frame
setPositions(pos.map(pos => {
return [
pos.x + Math.sin(angle + pos.x) * 35,
pos.y + Math.cos(angle + pos.y) * 10,
pos.z + Math.sin(angle + pos.z) * 35,
]
}))
});
cause this code feels awkward and crash my website.