I’ve a script which I attach to entities that I always want to look at camera.
Here’s the script
LookAtCamera.prototype.initialize = function () {
this.camera = this.app.root.findByName('Camera');
this.player = this.camera.findByName('Player');
};
// update code called every frame
LookAtCamera.prototype.update = function (dt) {
if (this.app.xr.active) {
// this.entity.lookAt(this.app.xr.camera.getPosition(), pc.Vec3.ZERO);
this.entity.lookAt(this.player.getPosition(), pc.Vec3.ZERO);
} else {
this.entity.lookAt(this.camera.getPosition(), pc.Vec3.ZERO);//, pc.Vec3.ZERO);
}
};
This works fine in web mode, but when I enter VR mode, all the objects don’t look at the camera. They behave weirdly, when I move the controller, the rotate. How can I fix this issue in VR.
Thanks,
Mahesh
P.S: Can I have a common line for both web and VR, where they always look at the camera irrespective of the mode.