pmndrs/use-p2

Body 'damping' and 'linearDamping' prop name inconsistency breaks providing 'linearDamping' in body hook props

Opened this issue · 0 comments

I noticed that the linear damping prop in use-p2 is called linearDamping (same as cannon), but in the p2 lib it is called damping.

Setting linearDamping via the body hook api works, as the setLinearDamping op sets the damping property correctly:

e.g.

const Example = () => {
  const [_, api] = useCircle(...)

  useEffect(() => {
    api.linearDamping.set(someValue) // this works!
  }, [])
  
  // ...
}

But providing linearDamping in the props of a body hook doesn't work. From a quick look, it appears that's because propsToBody doesn't have any handling for the linearDamping -> damping property name mismatch.

e.g.

const Example = () => {
  const [_, api] = useCircle({
    linearDamping: someValue, // this doesn't work!
    damping: someValue, // this works as it's passed through to `propsToBody`, but conflicts with our types!
  })

  // ...
}

I can think of a few options for fixing this:

  1. We could rename the prop from linearDamping -> damping in this lib to be consistent with p2

  2. We could update propsToBody and keep the API in as-is

  3. Once we start using p2-es in this lib, we could rename damping to linearDamping in p2-es for consistency with cannon