pmndrs / use-cannon

👋💣 physics based hooks for @react-three/fiber
https://cannon.pmnd.rs
2.76k stars 154 forks source link

`applyForce` and `applyLocalForce` gives error #205

Closed hazem3500 closed 3 years ago

hazem3500 commented 3 years ago

Calling applyForce or applyLocalForce gives an error

Uncaught TypeError: Found non-callable @@iterator
    at self.onmessage (worker.js:273)

Example

function ScalableBall() {
  const [ref, api] = useSphere(() => ({
    mass: 1,
    args: 1,
    position: [0, 1, 0],
  }))

  function scale() {
    api.applyForce(new Vec3(5, 5, 5), new Vec3(0, -1, 0))
  }

  return (
    <mesh ref={ref} onClick={scale}>
      <sphereGeometry args={[1]} />
      <meshBasicMaterial color="blue" />
    </mesh>
  )
}

Live Demo

See the console from the browser dev-tools

stockhuman commented 3 years ago

Hey there, I can't reproduce this upon cleaning up your example (updating dependencies, etc), but the world is not defined error it later produced may be just fixed in master. Could you try that?

drcmda commented 3 years ago

applyForce: (force: number[], worldPoint: number[]) => void

can it be you're feeding it classes?

stockhuman commented 3 years ago

Oh, yeah, I should've said: I also passed number arrays.

Edit: closing as I can't reproduce.

calvind777 commented 3 years ago

I'm also having this same issue (not with applyForce, with useSphere), when converting a functioning component that uses useBox to use useSphere instead. Will try to make a working example in a sandbox