Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions tslib/charactercontroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class CharacterController
onGround : boolean;
dead : boolean;
god : boolean;
disableGod : boolean;

walkDirection : any; // v3

Expand Down Expand Up @@ -132,6 +133,7 @@ class CharacterController
c.onGround = false;
c.dead = false;
c.god = false;
c.disableGod = false;

if (params)
{
Expand All @@ -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.disableGod = params.disableGod != null ? params.disableGod : c.disableGod;
}

var at = md.m43At(matrix);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
};

Expand Down Expand Up @@ -543,6 +528,24 @@ class CharacterController
return c;
}

setGod(newGod)
{
if (newGod && this.disableGod)
{
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;
Expand Down