Table Of Contents

Previous topic

19. Low Level 3D Physics API

Next topic

19.2. The CollisionObject Object

This Page

19.1. The Character Object

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.

19.1.1. Constructor

A Character object can be constructed with PhysicsDevice.createCharacter.

19.1.2. Methods

19.1.2.1. calculateTransform

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.

19.1.2.2. calculateExtents

Summary

Calculates the world extents of the character.

Syntax

var extents = [];
character.calculateExtents(extents);
extents
The world extents of the character.

19.1.2.3. jump

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();

19.1.3. Properties

19.1.3.1. velocity

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);

19.1.3.2. position

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);

19.1.3.3. onGround

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

19.1.3.4. crouch

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;
}

19.1.3.5. dead

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;
}

19.1.3.6. maxJumpHeight

Summary

The maximum height the character will jump upwards.

Syntax

character.maxJumpHeight = 10.0;

19.1.3.7. userData

Summary

The user object associated with the character.

Syntax

// Get current user object
var sceneOwner = character.userData;

// Set a new one
character.userData = enemyEntity;