cameraPath: the user’s movement must follow the path defined by system.
The user can enable only one script at the same time. So I need to enable/disable the other script dynamically.
Here is my scripts of camera:
FpsCamera.prototype.initialize = function() {
console.log('fps camera initialize.');
this._initialize();
this.on("state", function (enabled) {
console.log('state changed: ', enabled);
});
this.on('enable', function() {
console.log('fps camera enabled.');
this._initialize();
});
this.on('disable', function() {
console.log('fps camera disabled.');
this.entity.collision.off('collisionstart');
});
};
CameraPath.prototype.initialize = function() {
console.log('camera path initialize.');
this.camera = this.entity.findByName('Camera');
this.createPath();
this.on("attr:pathRoot", function (value, prev) {
if (value) {
this.createPath();
this.time = 0;
}
});
this.on("attr:time", function (value, prev) {
this.time = pc.math.clamp(this.startTime, 0, this.duration);
});
this.time = pc.math.clamp(this.startTime, 0, this.duration);
// Caching some Vec3 objects that will be used in the update loop continously
// so we don't keep triggering the garbage collector
this.lookAt = new pc.Vec3();
this.up = new pc.Vec3();
};
You can try add a line when you swap cameras after you disable the script and enable the new one you can call a initCam function with the instructions you need to fire.
Well as example in my initialize function i have set lot of variables, and if i disable and enable back the entity/script the initialize is not fired again so i moved all that i had in initialize into initCall function and inside initialize i just have this.initCall() the same when i enable back the function this.player.script.fpsCamera.enabled=true;
this.player.script.fpsCamera.initCall();
I think the problem is that the touchInput start as disabled and i don’t see the activate attribute you talked about earlier, so my guess it’s that the initialize funtions of touchInput is not properly fired. But i can be wrong. You enable touchInput and make it load before the mouseInput and when mouseInput is initialized you disable touchInput.
Yes, this project does not apply my workaround solution(add activate attribute).
My idea is the same as yours. Maybe I need to call the initialize function of touchInput manually. Something like: