pmndrs / cannon-es

💣 A lightweight 3D physics engine written in JavaScript.
https://pmndrs.github.io/cannon-es/
MIT License
1.76k stars 132 forks source link

Support Cone Shape #64

Open bachphuc opened 3 years ago

bachphuc commented 3 years ago

Hi, Thanks for great library and great team.

I'm learning about ThreeJs and Cannon-es. In my example I'm working with Cylinder but I see Cylinder is not working well. I create a cylinder and sphere then when I click by mouse I make sphere run then sphere goes through Cylinder. It shouldn't.

Screenshot 2021-01-11 100444

This is full my example. example.zip

Thanks

marcofugaro commented 3 years ago

The issue is that you're trying to make a cone body, the Cylinder shape doesn't work if you pass 0 as radiusTop or radiusBottom.

Cannon doesn't support a cylinder shape yet, for the moment you can bypass this by doing

const cylinderShape = new CANNON.Cylinder(0.01, 3, CYLINDER_HEIGHT, 4, 1);

PS orbit-controls-es6 is not maintained anymore, you can import OrbitControls directly from three (which is better maintained) like this:

import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
bachphuc commented 3 years ago

Thank @marcofugaro for the quick response. I tried your suggestion and It works. While Cannon hasn't supported cone body then this can be good trick.