jumpController
Permet à un objet d'être controllé par un joueur
require
alive()body()triggers on self
"jump""double jump""moved"parameters
| Parameter | Default Value | Type | Description |
|---|---|---|---|
jumpKey | string | "up" | |
jumpForce | number | 1000 | |
airjumpForce | number | 800 | |
doubleJump | number | 0 |
example
jumpController({ jumpKey: "up", jumpForce: 1000, airjumpForce: 800, doubleJump: 0}),function jumpController(p) { const param = { jumpKey: "up", jumpForce: 1000, airjumpForce: 800, doubleJump: 0, ...p, } return { id: "jumpController", jumpCount: 0, require: ["alive", "body"], isPassingThrough: 0, jumpReduction: 0, add() { onKeyPress(param.jumpKey, () => { if (this.isAlive && !this.isClimbing) { if (this.isGrounded()) this.trigger("jump") else if (this.jumpCount < param.doubleJump) this.trigger("double jump") } }) this.onGround(() => (this.jumpCount = 0)) this.on("jump", () => { const surfaceJumpReduction = (() => { if (!this.isGrounded()) return 0 else return this.curPlatform().jumpReduction || 0 })() this.jump(param.jumpForce / (surfaceJumpReduction + 1)) this.trigger("moved"); }) this.on("double jump", () => { this.jump(param.airjumpForce) this.jumpCount++ this.trigger("moved") }) }, }}