A Character object represents a rigid body with added features that simplify the creation of character entities. The volume of the character will be represented by either two spheres seating one on top of each other or a capsule (Canvas vs Plugin), changing their relative vertical location according to the crouch or dead states. Due to the vertical symmetry of the two spheres the character object lacks orientation.
A Character object can be constructed with PhysicsDevice.createCharacter.
Summary
Calculates the world matrix of the character.
Syntax
var transform = mathDevice.m43BuildIdentity();
var n, character, node;
for (n = 0; n < numNodes; n += 1)
{
character = characters[n];
node = nodes[n];
character.calculateTransform(transform, node.origin);
drawNode(node, transform);
}
The transform parameter should be a Matrix43 object and it will be set to the world matrix of the character.
The optional origin parameter can be used to offset the world matrix.
Summary
Calculates the world extents of the character.
Syntax
var extents = [];
character.calculateExtents(extents);
Summary
Makes the character jump in the direction of the velocity vector.
This method has no effect if character is not a Physics world.
Syntax
character.jump();
Summary
The Vector3 object representing the linear velocity of the character.
Syntax
// Get the current velocity
var velocity = character.velocity;
// Double it
character.velocity = mathDevice.v3Add(velocity, velocity);
Summary
The Vector3 object representing the current location of the character.
Syntax
// Get the current position
var position = character.position;
// Move it to the origin
character.position = mathDevice.v3Build(0, 0, 0);
Summary
True if the character is on the ground, false otherwise. Querying this property triggers a convex sweep test from the current position of the character downwards in order to check for any collisions with non-vertical surfaces.
Syntax
if (character.onGround)
{
character.jump();
}
Note
Read Only
Summary
True if the character is on a crouch state.
Setting this property to true will trigger a transition to the crouch state which halves the height of the character, unless the character is on a dead state. Setting this property to false will make the character stand up.
Syntax
if (!character.crouch)
{
character.crouch = true;
}
Summary
True if the character is on a dead state.
Setting this property to true will trigger a transition to the dead state which sets the height of the character to its radius. Setting this property to false will make the character stand up.
Syntax
if (!character.dead)
{
character.dead = true;
}
Summary
The maximum height the character will jump upwards.
Syntax
character.maxJumpHeight = 10.0;
Summary
The user object associated with the character.
Syntax
// Get current user object
var sceneOwner = character.userData;
// Set a new one
character.userData = enemyEntity;