Skip to content

Give a position to update camera #1230

Answered by drcmda
MakitaToki asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@MakitaToki
Comment options

@arwenpi
Comment options

@MakitaToki
Comment options

Answer selected by MakitaToki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants