Give a position to update camera #1230
-
I get stuck in camera animation. I want to implement following effect: a component can receive a prop representing camera position, such as an array or threejs Camera class, and this change can be animated when I click button to update this prop by giving a new camera position. Currently, the project is like here, but there are some problems:
Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
i think you're making it way too complicated: https://codesandbox.io/s/framer-motion-camera-focus-nsb7f?file=/src/App.js (click the sphere) you have a camera and you can access it anywhere: // in any component
const camera = useThree(state => state.camera)
// or in useFrame
useFrame(state => {
state.camera ...
}) the easiest animation is lerp. const vec = new THREE.Vector3()
function Foo() {
// ...
camera.position.lerp(temp.set(x, y, z), friction) if you combine lerp with useFrame you have an animation ootb. x,y and z represent your target coordinates. how you propagate these through the scene is up to you. friction is how fast the animation is, try 0.1 for starters. |
Beta Was this translation helpful? Give feedback.
i think you're making it way too complicated: https://codesandbox.io/s/framer-motion-camera-focus-nsb7f?file=/src/App.js (click the sphere)
you have a camera and you can access it anywhere:
the easiest animation is lerp.
if you combine lerp with useFrame you have an animation ootb. x,y and z represent your target coordinates. how you propagate these through the scene is up to you. friction is how fast the animation is, try 0.1 for starters.