David Evans
Co-founder and CTO at PlayCanvas
var e = context.root.findByName(entityName);
e.script.send(scriptName, functionName, arg1, arg2 ... argN);
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)); }
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()); }
Format | Chrome | Firefox | IE | Opera | Safari |
---|---|---|---|---|---|
WAVE, PCM | ✔ | ✔ | ✘ |
✔ |
✔ |
WebM, Vorbis | ✔ | ✔ | ✘ | ✔ | ✘ |
Ogg, Vorbis | ✔ | ✔ | ✘ | ✔ | ✘ |
MP4, MP3 | ✔ | ✔ | ✔ |
✔ |
✔ |
MP4, AAC | ✔ | ✔ | ✔ |
✔ |
✔ |
update: function (dt) { if (context.keyboard.wasPressed(pc.input.KEY_SPACE) && onGround) { this.entity.audiosource.play('jump_sound'); } }
update: function (dt) { this.timer += dt; this.entity.audiosource.volume = Math.sin(this.timer) * 0.5 + 0.5; }
By David Evans
A beginners guide to PlayCanvas, the online, collaborative game making platform.