Skip to content

Commit

Permalink
feat: improve collision detection + add collisions to 2d
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugustinette committed Aug 6, 2024
1 parent 1870009 commit 8d1d863
Show file tree
Hide file tree
Showing 27 changed files with 446 additions and 310 deletions.
6 changes: 6 additions & 0 deletions apps/playground-2d/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ import MySquare from './classes/MySquare'
sprite.setPosition(2, 3)
sprite.initRigidBody()
sprite.setScaleWidth(0.5)
sprite.onCollisionWith(FSquare, () => {
console.log('Sprite collided with a square!')
})
sprite.onCollisionWith(circle, () => {
console.log('Sprite collided with the circle!')
})
})
scene.addComponent(sprite)

Expand Down
10 changes: 5 additions & 5 deletions apps/playground-3d/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import './style.css'
cube.initRigidBody({
shape: F3dShapes.SPHERE,
})
cube.onCollisionWith(FSphere, () => {
console.log('Cube collided with a Sphere!')
})
scene.addComponent(cube)

const sphere = new FSphere(scene)
Expand All @@ -44,8 +41,11 @@ import './style.css'
gltfCube2.setPosition(2, 5, 2)
scene.addComponent(gltfCube2)

cube.onCollisionWith(gltfCube, () => {
console.log('Cube collided with the gltfCube!')
cube.onCollisionWith(GltfCube, () => {
console.log('Cube collided with a GltfCube !')
})
cube.onCollisionWith(sphere, () => {
console.log('Cube collided with the sphere!')
})

// After 3 seconds, add a third gltfCube
Expand Down
32 changes: 16 additions & 16 deletions docs/api/2d/classes/FCircle.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ scene.addComponent(circle)

#### Defined in

[packages/2d/src/polygons/FCircle.ts:20](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/polygons/FCircle.ts#L20)
[packages/2d/src/polygons/FCircle.ts:20](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/polygons/FCircle.ts#L20)

## Methods

Expand Down Expand Up @@ -139,7 +139,7 @@ component.initCollider({

#### Defined in

[packages/2d/src/polygons/FCircle.ts:44](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/polygons/FCircle.ts#L44)
[packages/2d/src/polygons/FCircle.ts:44](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/polygons/FCircle.ts#L44)

***

Expand Down Expand Up @@ -194,7 +194,7 @@ component.initRigidBody({

#### Defined in

[packages/2d/src/polygons/FCircle.ts:32](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/polygons/FCircle.ts#L32)
[packages/2d/src/polygons/FCircle.ts:32](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/polygons/FCircle.ts#L32)

***

Expand Down Expand Up @@ -244,7 +244,7 @@ player.onCollisionWith(enemy, () => {

#### Defined in

packages/core/dist/index.d.ts:48
[packages/2d/src/FComponent2d.ts:252](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L252)

***

Expand All @@ -271,7 +271,7 @@ Should be called every frame.

#### Defined in

[packages/2d/src/polygons/FCircle.ts:28](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/polygons/FCircle.ts#L28)
[packages/2d/src/polygons/FCircle.ts:28](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/polygons/FCircle.ts#L28)

***

Expand Down Expand Up @@ -309,7 +309,7 @@ component.setPosition(0, 0)

#### Defined in

[packages/2d/src/FComponent2d.ts:100](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L100)
[packages/2d/src/FComponent2d.ts:100](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L100)

***

Expand Down Expand Up @@ -343,7 +343,7 @@ component.setRotation(Math.PI / 2)

#### Defined in

[packages/2d/src/FComponent2d.ts:131](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L131)
[packages/2d/src/FComponent2d.ts:131](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L131)

***

Expand Down Expand Up @@ -377,7 +377,7 @@ component.setRotationDegree(90)

#### Defined in

[packages/2d/src/FComponent2d.ts:144](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L144)
[packages/2d/src/FComponent2d.ts:144](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L144)

***

Expand Down Expand Up @@ -415,7 +415,7 @@ component.setScale(1, 1)

#### Defined in

[packages/2d/src/FComponent2d.ts:114](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L114)
[packages/2d/src/FComponent2d.ts:114](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L114)

## Properties

Expand Down Expand Up @@ -473,7 +473,7 @@ RAPIER Collider

#### Defined in

[packages/2d/src/FComponent2d.ts:46](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L46)
[packages/2d/src/FComponent2d.ts:46](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L46)

***

Expand All @@ -489,7 +489,7 @@ PIXI container

#### Defined in

[packages/2d/src/FComponent2d.ts:22](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L22)
[packages/2d/src/FComponent2d.ts:22](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L22)

***

Expand All @@ -505,7 +505,7 @@ Position of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:28](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L28)
[packages/2d/src/FComponent2d.ts:28](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L28)

***

Expand All @@ -521,7 +521,7 @@ RAPIER RigidBody

#### Defined in

[packages/2d/src/FComponent2d.ts:42](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L42)
[packages/2d/src/FComponent2d.ts:42](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L42)

***

Expand All @@ -537,7 +537,7 @@ Rotation of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:36](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L36)
[packages/2d/src/FComponent2d.ts:36](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L36)

***

Expand All @@ -553,7 +553,7 @@ Scale of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:32](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L32)
[packages/2d/src/FComponent2d.ts:32](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L32)

***

Expand All @@ -569,4 +569,4 @@ The scene which the component is in.

#### Defined in

[packages/2d/src/FComponent2d.ts:17](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L17)
[packages/2d/src/FComponent2d.ts:17](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L17)
34 changes: 17 additions & 17 deletions docs/api/2d/classes/FComponent2d.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The 2D scene where the component will be added.

#### Defined in

[packages/2d/src/FComponent2d.ts:51](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L51)
[packages/2d/src/FComponent2d.ts:51](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L51)

## Methods

Expand Down Expand Up @@ -132,7 +132,7 @@ component.initCollider({

#### Defined in

[packages/2d/src/FComponent2d.ts:220](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L220)
[packages/2d/src/FComponent2d.ts:220](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L220)

***

Expand Down Expand Up @@ -183,7 +183,7 @@ component.initRigidBody({

#### Defined in

[packages/2d/src/FComponent2d.ts:165](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L165)
[packages/2d/src/FComponent2d.ts:165](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L165)

***

Expand Down Expand Up @@ -227,13 +227,13 @@ player.onCollisionWith(enemy, () => {
})
```

#### Inherited from
#### Overrides

`FComponent.onCollisionWith`

#### Defined in

packages/core/dist/index.d.ts:48
[packages/2d/src/FComponent2d.ts:252](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L252)

***

Expand All @@ -260,7 +260,7 @@ Should be called every frame.

#### Defined in

[packages/2d/src/FComponent2d.ts:68](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L68)
[packages/2d/src/FComponent2d.ts:68](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L68)

***

Expand Down Expand Up @@ -294,7 +294,7 @@ component.setPosition(0, 0)

#### Defined in

[packages/2d/src/FComponent2d.ts:100](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L100)
[packages/2d/src/FComponent2d.ts:100](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L100)

***

Expand Down Expand Up @@ -324,7 +324,7 @@ component.setRotation(Math.PI / 2)

#### Defined in

[packages/2d/src/FComponent2d.ts:131](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L131)
[packages/2d/src/FComponent2d.ts:131](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L131)

***

Expand Down Expand Up @@ -354,7 +354,7 @@ component.setRotationDegree(90)

#### Defined in

[packages/2d/src/FComponent2d.ts:144](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L144)
[packages/2d/src/FComponent2d.ts:144](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L144)

***

Expand Down Expand Up @@ -388,7 +388,7 @@ component.setScale(1, 1)

#### Defined in

[packages/2d/src/FComponent2d.ts:114](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L114)
[packages/2d/src/FComponent2d.ts:114](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L114)

## Properties

Expand Down Expand Up @@ -442,7 +442,7 @@ RAPIER Collider

#### Defined in

[packages/2d/src/FComponent2d.ts:46](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L46)
[packages/2d/src/FComponent2d.ts:46](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L46)

***

Expand All @@ -454,7 +454,7 @@ PIXI container

#### Defined in

[packages/2d/src/FComponent2d.ts:22](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L22)
[packages/2d/src/FComponent2d.ts:22](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L22)

***

Expand All @@ -466,7 +466,7 @@ Position of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:28](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L28)
[packages/2d/src/FComponent2d.ts:28](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L28)

***

Expand All @@ -478,7 +478,7 @@ RAPIER RigidBody

#### Defined in

[packages/2d/src/FComponent2d.ts:42](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L42)
[packages/2d/src/FComponent2d.ts:42](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L42)

***

Expand All @@ -490,7 +490,7 @@ Rotation of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:36](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L36)
[packages/2d/src/FComponent2d.ts:36](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L36)

***

Expand All @@ -502,7 +502,7 @@ Scale of the component.

#### Defined in

[packages/2d/src/FComponent2d.ts:32](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L32)
[packages/2d/src/FComponent2d.ts:32](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L32)

***

Expand All @@ -514,4 +514,4 @@ The scene which the component is in.

#### Defined in

[packages/2d/src/FComponent2d.ts:17](https://github.com/fibbojs/fibbo/blob/2b94dbe5ad7abc15b8f9f57b33427a79de05c36b/packages/2d/src/FComponent2d.ts#L17)
[packages/2d/src/FComponent2d.ts:17](https://github.com/fibbojs/fibbo/blob/1870009ccb8291e46b08992d55a2056e8625aa96/packages/2d/src/FComponent2d.ts#L17)
Loading

0 comments on commit 8d1d863

Please sign in to comment.