My app has keyboard input which works fine when launched from the editor, and indeed when hosted elsewhere but not when published on playcanvas - wierd huh!
part 2 works fine - with first-person controller & physics
but part 1 does not - uses the hammer.min and camera scripts adapted from the standard ‘3d model viewer’ .
Update - I think it may be that I am setting global variables, need to try with an adapted version using only vars created inside playcanvas…
Try clicking with mouse first on screen of a game (iframe).
There is a “problem” where user is required to click by mouse onto iframe before it starts to accept keyboard input. This is general mechanics that browsers have. So if your game is in iframe - you need to ask players to click with mouse onto something first, this can be just a menu or something like so.
Just checked this link: http://playcanv.as/p/m46Q6B5l
Keyboard and mouse seems to work, is the problem already resolved? And if so, what it was related to?
It looks like this works if you click on the iFrame and then hit TAB. So it seems that something takes focus away from the iframe. How about doing this in the initialize method of a script:
setTimeout(function() {window.focus();})
I’m not sure if this will work like that but give it a go and if not I’m gonna fork your project and try some stuff out.
OK great #. problem solved for now, - I am happy to ask users to hit tab to start.
for posterity heres more detail:
adding that window focus line:
setTimeout(function() {window.focus();})
Also solves the problem, but meanwhile it also disrupts the scaling of the model on screen, which is done in the camerascript, in turn relating to hammer.min.js
the scaling is controlled by these lines:
if (meshInstances.length > 0) {
var aabb = new pc.shape.Aabb();
aabb.copy(meshInstances[0].aabb);
for (i = 0; i < meshInstances.length; i++) {
aabb.add(meshInstances[i].aabb);
}
var focus = aabb.center;
var halfHeight = aabb.halfExtents.y/2; //**/2 to scale the model to fill screen**
var halfDepth = aabb.halfExtents.z/2; //**/2**
var offset = 1.5 * halfHeight / Math.tan(0.5 * this.entity.camera.fov * Math.PI / 180.0);
this.reset(focus, offset + halfDepth);
} else {
this.reset(pc.Vec3.ZERO, 3);
}
},