Hello, seems i have lost my touch after 1yr far from coding, i want move the camera from A to B so i made this 3 functions, but seems i missed something, since camera ignore me
update: function (dt) {
app.mouse.on(pc.EVENT_MOUSEDOWN, this.onMouseDown, this);
if (this.state==='move') {
/*var position = this.entity.getPosition();
position.lerp(this.entity.getPosition(),this.targetPosition,0.1);
this.entity.setPosition(position);
*/temp.sub2(this.targetPosition, this.entity.getPosition());
distance = temp.length();
if (distance < this.walkAnimCutoff) {
this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
this.state="idle";
}
temp.normalize().scale(this.moveSpeed);
this.entity.rigidbody.linearVelocity = temp;
temp.sub2(this.entity.getPosition(), this.targetPosition);
this.entity.rigidbody.syncEntityToBody();
}
},
onMouseDown: function (e) {
if (e.button === pc.MOUSEBUTTON_LEFT) {
this.moveTo(0.68,3.657,-1);
}
},
moveTo: function (position) {
this.moveTimer = 0.4;
this.startPosition.copy(this.entity.getPosition());
this.targetPosition.copy(position);
this.state='move';
},
Some of the script syntax is different but the API is mostly the same. You may need @will or @codebon to fork your project for you with new scripting system enabled?
modified the code, i still miss something to make the camera move forward the destination
pc.script.create('cameraCinematic', function (app) {
// Creates a new CameraCinematic instance
var temp = new pc.Vec3();
var CameraCinematic = function (entity) {
this.entity = entity;
this.startPosition = new pc.Vec3();
this.targetPosition = new pc.Vec3();
this.state='idle';
this.entity.rigidbody.enabled=true;
};
CameraCinematic.prototype = {
// Called once after all resources are loaded and before the first update
initialize: function () {
this.entity.position=this.entity.getPosition();
app.mouse.on("mousedown", this.onMouseDown, this);
},
// Called every frame, dt is time in seconds since last update
update: function (dt) {
app.mouse.on("mousedown", this.onMouseDown, this);
if (this.state==='move') {
/*var position = this.entity.getPosition();
position.lerp(this.entity.getPosition(),this.targetPosition,0.1);
this.entity.setPosition(position);
*/temp.sub2(this.targetPosition, this.entity.getPosition());
distance = temp.length();
if (distance < 0.8) {
this.entity.rigidbody.linearVelocity = pc.Vec3.ZERO;
this.state="idle";
}
temp.normalize().scale(0.15);
this.entity.rigidbody.linearVelocity = temp;
temp.sub2(this.entity.getPosition(), this.targetPosition);
}
},
onMouseDown: function (e) {
if (e.button === pc.MOUSEBUTTON_LEFT) {
var dest=new pc.Vec3(0.68,3.657,-1);
this.moveTo(dest);
}
},
moveTo: function (position) {
this.startPosition.copy(this.entity.getPosition());
this.targetPosition.copy(position);
this.state='move';
},
};
return CameraCinematic;
});
thanks a lot @DevPlex01 i knew that soon or later i would have to go through that, i was just lazy coz of the size of the project. Well i will summon all my patience
update: function (dt) {
app.mouse.on("mousedown", this.onMouseDown, this);
if (this.state==='move') {
var dest=new pc.Vec3(0.68,2.657,-0.5);
this.moveTo(dest);
}
},
onMouseDown: function (e) {
if (e.button === pc.MOUSEBUTTON_LEFT && this.state=="idle") {
var dest=new pc.Vec3(0.68,2.657,-1);
this.moveTo(dest);
}
},
moveTo: function (position) {
this.startPosition.copy(this.entity.getPosition());
this.targetPosition.copy(position);
this.state='move';
var position = new pc.Vec3();
position.lerp(this.targetPosition,this.startPosition,0.99);
this.entity.setPosition(position);
this.entity.rigidbody.syncEntityToBody();
},
@DevPlex01 thanks for the help to remove dust, i will translate it tomorrow getting my sweet time (i have used binary just for math so i need to investigate about letters lol) @will ok thanks I will change it