Graphics
- Ambient, directional, point and spot lights
- Static and skinned meshes (up to 256 bones)
- Physically Based Rendering
- Shadow mapping
- Particles
-
Per-pixel fog
- Skyboxes
- Full screen effects
Models: Simple primitives
Basic shapes: box, sphere, cylinder, cone, capsule
Very useful for prototyping
Can make entire games with them:
Models: Assets
3D content that you upload to PlayCanvas
Recommendations:
Supply models in FBX format
Ensure textures are embedded in FBX
Ensure no meshes have >65535 vertices
Material Editing
You can edit materials in Designer
Click once to select entity
Click again to select the material on selected mesh
Shadows
Shadows add realism to your scene
Limitations
Keep the number of dynamic lights low
There is a light budget and each light type has a 'cost'
Directionals are cheapest, then points, then spots
Scene Settings
You can set ambient light level, fog and gravity in Designer
Physics
Allows you to quickly create complex and
realistic behavior and interactions
Rigid BOdy
Idealised representation of a body
in which deformation is ignored
Properties:
- position and orientation
- linear and angular velocity
- mass, friction, restitution
Actions:
- apply forces and impulses
- apply torque and torque impulses
Body Types
Let's see each type in
action...
Collision Primitives
A body needs to be linked to a collision primitive:
- Sphere
- Box
- Capsule
- Cylinder
- Triangle Mesh
Ray Casting
- Visibility checks
- Lasers
- Character controllers
checkGround: function () {
var start = this.entity.getPosition();
var end = start.clone();
end.y -= 1.1;
this.onGround = false;
// Fire ray straight down to just below the bottom of rigid body
// If it hits something, the character is on the ground
context.systems.rigidbody.raycastFirst(start, end, function (res) {
this.onGround = true;
}.bind(this));
}
Contact Detection
Useful for triggering events
e.g. audio, particles
initialize: function () {
this.entity.collision.on('collisionstart', this.onHit, this);
},
onHit: function (result) {
var a = this.entity;
var b = result.other;
console.log(a.getName() + ' has touched ' + b.getName());
}
Let's Try It!
-
Create a new pack
- Rename root node 'Physics'
-
Create a camera
- Create a static floor
(components: model, collision and rigidbody)
- Create a dynamic ball above floor
(same components as above)
- Set ball rigidbody 'Type' to 'Dynamic'
- Launch!
Audio
Brings your game to life more
than you might think.
Don't make it an afterthought!
Supported Formats
PlayCanvas doesn't currently
handle multiple audio formats
Pick what works best based on your audience
Format |
Chrome |
Firefox |
IE |
Opera |
Safari |
WAVE, PCM |
✔ |
✔ |
✘ |
✔
|
✔ |
WebM, Vorbis |
✔ |
✔ |
✘ |
✔ |
✘ |
Ogg, Vorbis |
✔ |
✔ |
✘ |
✔ |
✘ |
MP4, MP3 |
✔ |
✔ |
✔ |
✔
|
✔ |
MP4, AAC |
✔ |
✔ |
✔ |
✔
|
✔ |
Sources and Listeners
Listener component locates your ear in 3D space
Normally assigned to the game camera
Sources play back sound FX
Controlling Audio from Script
Example 1: trigger audio on some event
update: function (dt) {
if (context.keyboard.wasPressed(pc.input.KEY_SPACE) && onGround) {
this.entity.audiosource.play('jump_sound');
}
}
Example 2: modify audio source properties over time
update: function (dt) {
this.timer += dt;
this.entity.audiosource.volume = Math.sin(this.timer) * 0.5 + 0.5;
}