michalbe / cervus

:video_game: tiny WebGL 3d game engine
MIT License
28 stars 4 forks source link

Different collider shapes #119

Open michalbe opened 6 years ago

michalbe commented 6 years ago

Right now cervus uses only the box collider in the RigidBody component (PR #118), but @chandlerprall's GoblinPhysics engine (the one we're using in our rb) has a built in support for eight different shapes. I feel like new physics.colliders[this.shape] call in components/rigid_body should pass entity's Transform component to the constructor, and all the magic (with different shapes expecting different arguments) should happen inside the physics module.

stasm commented 6 years ago

The Transform component should only store the information about the position and the rotation of the center of the entity and its scale. In particular it shouldn't know anything about the bounds of the entity.

The Render component has the information about the bounds via vertices but using that for the physics engine is likely an overkill in most cases. I suggest adding a Collider component with a type, or perhaps a few different collider components: BoxCollider, SphereColiider etc.