movingBackAndForth
Permet à un objet de déplacer dans une direction puis dans le sens inverse en recontrant un objet "stopper"
triggers on self
"U-turn"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
direction | vec2 | vec2(1, 0) | |
speed | number | 100 | |
switchDelay | number | 1 |
example
movingBackAndForth({ direction: vec2(1, 0), speed: 100, switchDelay: 1}),function movingBackAndForth(p) { const param = { direction: vec2(1, 0), speed: 100, switchDelay: 1, ...p } return { direction: vec2(param.direction).unit(), facing: 1, add() { this.onCollide("stopper", () => { tween( this.direction, this.direction.scale(-1), param.switchDelay, (v) => (this.direction = v), easings.easeOutSine ) this.trigger("U-turn") }) }, update() { this.move(this.direction.scale(param.speed)) if (this.direction.len() > 0.1) this.facing = this.direction.unit().x }, }}