This code is currently functioning flawlessly:
const [value, update] = useReducer((x) => (x % 4) + 1, 20);
useFrame(({ controller }) => {
if (element?.current) {
controller?.ray?.at(value, element?.current?.position);
}
});
Check out the live demo here: https://codesandbox.io/s/r3f-mouse-to-world-elh73?file=/src/index.js:311-315
Are you wondering how to incorporate a slight delay into the animation to prevent the object from instantly moving to the mouse position? Additionally, would you like to know how to introduce an offset so that the object is not directly at the center of the mouse pointer?