https://playcanvas.com/editor/code/1035705?tabs=120373166
var GetCameraData = pc.createScript('getCameraData');
GetCameraData.attributes.add('camera', {
type: 'entity'
});
GetCameraData.attributes.add('targetEntity', {
type: 'entity'
});
GetCameraData.attributes.add('entity1', {
type: 'entity'
});
GetCameraData.attributes.add('currentPoint', {
type: 'entity'
});
GetCameraData.attributes.add('posCurve', {
type: 'curve',
curves: ['x', 'y', 'z']
});
GetCameraData.attributes.add('lookAtCurve', {
type: 'curve',
curves: ['x', 'y', 'z']
});
GetCameraData.attributes.add("duration", {
type: "number",
default: 3
});
// initialize code called once per entity
GetCameraData.prototype.initialize = function () {
var that = this;
this.time = 0;
this.app.addTweenManager();
this.curvePosition = new pc.Vec3();
this.lookAtPosition = new pc.Vec3();
this.curveState = false;
this.entity.button.on('click', function () {
// that.cameraData();
this.curveState = true;
}, this);
};
// update code called every frame
GetCameraData.prototype.update = function (dt) {
var that = this;
this.time += dt;
if (this.app.keyboard.wasPressed(pc.KEY_1)) {
// this.useTime();
// this.useTween();
this.curveState = true;
}
if (this.curveState == true) {
if (that.time > that.duration) return;
var percent = that.time / that.duration;
var curveValue = that.posCurve.value(percent);
var lookAtValue = that.lookAtCurve.value(percent);
// console.log(curveValue);
that.curvePosition.x = curveValue[0];
that.curvePosition.y = curveValue[1];
that.curvePosition.z = curveValue[2];
that.lookAtPosition.x = lookAtValue[0];
that.lookAtPosition.y = lookAtValue[1];
that.lookAtPosition.z = lookAtValue[2];
that.camera.script.orbitCamera.resetAndLookAtPoint(that.curvePosition, that.lookAtPosition);
}
};
// swap method called for script hot-reloading
// inherit your script state here
// GetCameraData.prototype.swap = function(old) { };
// to learn more about script anatomy, please read:
// https://developer.playcanvas.com/en/user-manual/scripting/
I want to use a lot of points in the curve. I don’t know if it will cause the main page to get stuck?