From 9121d6de41df13dd0606aa2ddbb5557087f99154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herbert=20Voj=C4=8D=C3=ADk?= Date: Mon, 31 Mar 2014 14:02:18 +0200 Subject: [PATCH 1/2] CharacterController has allowGod option --- tslib/charactercontroller.ts | 43 +++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/tslib/charactercontroller.ts b/tslib/charactercontroller.ts index ae7b564a..4eb3445f 100644 --- a/tslib/charactercontroller.ts +++ b/tslib/charactercontroller.ts @@ -54,6 +54,7 @@ class CharacterController onGround : boolean; dead : boolean; god : boolean; + allowGod : boolean; walkDirection : any; // v3 @@ -132,6 +133,7 @@ class CharacterController c.onGround = false; c.dead = false; c.god = false; + c.allowGod = true; if (params) { @@ -144,6 +146,7 @@ class CharacterController c.maxSpeed = params.maxSpeed || c.maxSpeed; c.maxStepHeight = params.maxStepHeight || c.maxStepHeight; c.maxJumpHeight = params.maxJumpHeight || c.maxJumpHeight; + c.allowGod = params.allowGod != null ? params.allowGod : c.allowGod; } var at = md.m43At(matrix); @@ -261,16 +264,7 @@ class CharacterController } if (keynum === keyCodes.G) { - c.god = !c.god; - if (c.god) - { - c.character.velocity = c.md.v3BuildZero(); - } - else - { - var characterPosition = c.md.m43Pos(c.matrix); - c.character.position = c.md.v3Add(characterPosition, c.physicsHeightOffset); - } + c.setGod(!c.god); } else if (keynum === keyCodes.RETURN) { @@ -383,16 +377,7 @@ class CharacterController } if (buttonnum === padCodes.BACK) { - c.god = !c.god; - if (c.god) - { - c.character.velocity = c.md.v3BuildZero(); - } - else - { - var characterPosition = c.md.m43Pos(c.matrix); - c.character.position = c.md.v3Add(characterPosition, c.physicsHeightOffset); - } + c.setGod(!c.god); } }; @@ -543,6 +528,24 @@ class CharacterController return c; } + setGod(newGod) + { + if (newGod && !this.allowGod) + { + return; + } + this.god = newGod; + if (this.god) + { + this.character.velocity = this.md.v3BuildZero(); + } + else + { + var characterPosition = this.md.m43Pos(this.matrix); + this.character.position = this.md.v3Add(characterPosition, this.physicsHeightOffset); + } + } + rotate(turn, pitch) { var md = this.md; From de041d1045cd3b86d1a85da4816cba93435b56a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herbert=20Voj=C4=8D=C3=ADk?= Date: Tue, 15 Apr 2014 10:11:30 +0200 Subject: [PATCH 2/2] using disableGod as option name --- tslib/charactercontroller.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tslib/charactercontroller.ts b/tslib/charactercontroller.ts index 4eb3445f..69a7eeba 100644 --- a/tslib/charactercontroller.ts +++ b/tslib/charactercontroller.ts @@ -54,7 +54,7 @@ class CharacterController onGround : boolean; dead : boolean; god : boolean; - allowGod : boolean; + disableGod : boolean; walkDirection : any; // v3 @@ -133,7 +133,7 @@ class CharacterController c.onGround = false; c.dead = false; c.god = false; - c.allowGod = true; + c.disableGod = false; if (params) { @@ -146,7 +146,7 @@ class CharacterController c.maxSpeed = params.maxSpeed || c.maxSpeed; c.maxStepHeight = params.maxStepHeight || c.maxStepHeight; c.maxJumpHeight = params.maxJumpHeight || c.maxJumpHeight; - c.allowGod = params.allowGod != null ? params.allowGod : c.allowGod; + c.disableGod = params.disableGod != null ? params.disableGod : c.disableGod; } var at = md.m43At(matrix); @@ -530,7 +530,7 @@ class CharacterController setGod(newGod) { - if (newGod && !this.allowGod) + if (newGod && this.disableGod) { return; }