Hello everyone.
I have an orbit-camera script in my project. I’m trying to move the camera to a certain position and I’m disabling the orbit-camera and enabling it again. What I want is to change the camera rotation also to loot at a certain part of the model. This is the code.
var nowpos = new pc.Vec3();
var newAngle = new pc.Vec3();
var cpos = new pc.Vec3(this.currentPos.x,this.currentPos.y,this.currentPos.z);
var tpos = new pc.Vec3(this.targetPos.x,this.targetPos.y,this.targetPos.z);
var cAngle = new pc.Vec3(this.currentAngle.x,this.currentAngle.y,this.currentAngle.z);
var tAngle = new pc.Vec3(this.targetAngle.x,this.targetAngle.y,this.targetAngle.z);
this.time += 0.01;
nowpos.lerp(cpos,tpos,this.time);
newAngle.lerp(cAngle,tAngle,this.time);
this.entity.setPosition(nowpos);
this.entity.setEulerAngles(newAngle);
this.app.fire('moveCamera:resetPoint',nowpos,this.targetEntity.getPosition());
if(this.time >= 1){
this.entity.script.orbitCamera.enabled = true;
this.orbitCamera.resetAndLookAtPoint(tpos, this.Target);
this.move = false;
this.time= 0;
this.prevPos = this.entity.getLocalPosition();
}
When I use resetAndLookAtPoint the camera angle changes. Is there any way to not change the camera angle?
Thank you
Project link: PlayCanvas | HTML5 Game Engine
Not sure I understand the issue. If you have a target position to look at and a target position for the camera to move to, it will set the orbit camera angle to match those two positions.
Looking at project when pressing ‘NEXT’ for the first time, it looks like the two positions you are setting to the orbit camera on resetAndLookAtPoint aren’t the same as the transition camera.
I didn’t get this point. I have passed targetPos, which is the position which I want to move the camera and this.Target is the position of the entity I want to look at.
What should passed to resetPoint and lookAtPoint?
Hi @yaustar and @Leonidas
I was wondering is there any way to not change the Z angle of the camera?
Because when I call the resetAndLookAtPoint(), the Z angle is set to zero in _updatePosition(). this.entity.setLocalEulerAngles(this._pitch, this._yaw, 0);
Thank you.
Unless you rolling the camera, Z will always be zero. If you rolling the camera, then you will need to modify orbit camera to calculate the Z when resetting.
I’m rolling the camera actually. The point where camera should move and its rotation, I’m copying to targetPos and targetAngle.
Is there any link or project that you can share to refer to calculate Z?
If you can take a look at this project(scene: bakelight and branch: Raycast), when you click Next button second time, you can observe the shift in camera angle.
Thank you.
if(this.time >= 1){
this.entity.script.orbitCamera.enabled = true;
// Make a new target look at point to be in front of the camera
var newTarget = this.entity.forward.clone().scale(2).add(newpos);
this.orbitCamera.resetAndLookAtPoint(newpos, newTarget);
this.move = false;
this.time= 0;
// this.prevPath = this.entity.getLocalPosition();
}
The issue is that when the camera is transitioning, it is only doing it via position and not in the direction that it s facing so the camera angle remains the same and the the previous target position is no longer valid.
Currently what we did is set the angles manually, i.e. keeping Z angle as 0 or 180 and change the X and Y angles accordingly to get the desired view. It works properly.