pmndrs / maath

🪶 Math helpers for the rest of us
https://maath.pmnd.rs
801 stars 15 forks source link

QUESTION damp3 eps #31

Closed thiagobrez closed 1 year ago

thiagobrez commented 1 year ago

Hi! This is just a question because I believe I'm using damp3 wrongly.

I'm trying to use damp3 to animate my camera position to focus on a moving object. My first try was this:

        damp3(
          camera.position,
          [
            groupRef.current.position.x,
            groupRef.current.position.y,
            groupRef.current.position.z + 2.5,
          ],
          0.25,
          delta,
        );

And it "works", but if the object is far away, it stops very far. See video ⬇️

https://user-images.githubusercontent.com/26878038/216608620-f92b6057-4a12-4a68-981a-b2ab6cf355ce.mov

Then I found out about the eps prop and it goes well with a high value, but then I loose easing, it just flies instantly:

        damp3(
          camera.position,
          [
            groupRef.current.position.x,
            groupRef.current.position.y,
            groupRef.current.position.z + 2.5,
          ],
          0.25,
          delta,
          undefined, // maxSpeed
          undefined, // easing
          1000, // eps
        );

https://user-images.githubusercontent.com/26878038/216609054-cab71d03-deac-43ed-ac6e-c13886e6e5b0.mov

Any tips on how I can focus on my object without it being too far away, and still keep the easing of the movement?

Thank you in advance!

drcmda commented 1 year ago

eps is the precision, try something like 0.000001 as in, go lower not higher.

thiagobrez commented 1 year ago

@drcmda Thanks for the prompt response. Going lower didn't do the trick, basically same result. But changing the easing function to other algorithms is going well. Currently trying easeInExpo (https://easings.net/#easeInExpo) and it's decent, combined with a lower maxSpeed. I'll play around with more and see what I prefer. Thank you!!