patroling
Permet à un objet de se déplacer jusqu'à ce qu'il recontre un objet
triggers on self
"U-turn"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
speed | number | 60 | |
direction | vec2 | vec2(-1, 0) | |
uTrunDelay | number | 0.5 | |
startDelay | number | 0.5 | |
crossEachOther | boolean | true |
example
patroling({ speed: 60, direction: vec2(-1, 0), uTrunDelay: 0.5, startDelay: 0.5, crossEachOther: true}),function patroling(p) { const param = { speed: 60, direction: vec2(-1, 0), uTrunDelay: 0.5, startDelay: 0.5, crossEachOther: true, ...p } return { direction: vec2(param.direction).unit(), resetDirection: vec2(param.direction).unit(), facing: 1, id: "partoling", add() { this.on("collide", (obj, col) => this.changeDirection(obj, col)) this.on("respawn", () => this.direction = this.resetDirection) if (param.crossEachOther) this.collisionIgnore.push("partoling") }, changeDirection(obj, col) { const l = col.isLeft() && this.direction.x < 0 const r = col.isRight() && this.direction.x > 0 if ((l || r) && !obj.is("player") && !obj.is("projectile")) { const n = this.direction.x > 0 ? -1 : 1 if (obj.is("stopper")) tween(this.direction.x, n, param.uTrunDelay, (v) => (this.direction.x = v), easings.easeInSin) else tween(0, n, param.startDelay, (v) => (this.direction.x = v), easings.easeInSin) } this.trigger("U-turn") }, update() { this.move(param.speed * this.direction.x, 0) if (this.direction.len() > 0.1) this.facing = this.direction.unit().x }, }}