bounce
Permet à un objet de se déplacer et de rebondir
parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
direction | vec2 | vec2(0, 0) | |
speed | number | 0 | |
bounciness | number | 0.8 | |
friction | number | 0.5 | |
detuneAmp | number | 400 | |
tag | string | "body" |
example
bounce({ direction: vec2(0, 0), speed: 0, bounciness: 0.8, friction: 0.5, detuneAmp: 400, tag: "body"}),function bounce(p) { const param = { direction: vec2(0, 0), speed: 0, bounciness: 0.8, friction: 0.5, detuneAmp: 400, tag: "body", ...p } return { id: "bouncing", bounceSpeed: 1, bouncedirection: param.direction, add() { this.onCollide(param.tag, (obj, col) => { const bouncing = ((d) => { this.vel = this.vel.scale(d) this.trigger("bounce", { volume: this.bounceSpeed, detune: this.bounceSpeed * param.detuneAmp }) }) if ((col.isTop() || col.isBottom())) bouncing(vec2(param.bounciness, - param.bounciness)) else if ((col.isLeft() || col.isRight())) bouncing(vec2(-param.bounciness, param.bounciness)) }) this.onCollideUpdate(param.tag, () => this.vel = this.vel.sub(this.vel.scale(param.friction * dt()))) }, }}