Hello,
I have camera with Orthographic Projection. And i am looking way to Smooth out Ortho Height.

I have set camera on car in side view. And i am handling ortho height according to speed of the car. But when car hit obstacle the ortho height change suddenly. Here is the code…
var speed = this.car.script.vehicle.speed;
this.entity.camera.orthoHeight = pc.math.clamp(this.camOrthoHeight + (Math.abs(speed)/50), 6, 9) ;
[Reference Unity] https://forum.unity.com/threads/2d-orthographic-smooth-zoom.312161/
Is there any way to smooth out camera Ortho Height in PlayCanvas?
Hi @Ketan_ATA,
I think in this case to properly smooth out this you need to take into account the dt between the frames and use a target & current ortho height values, lerping between the two.
Do you have a sample project for this to give it a try?
This issue has been resolved in private messages, @Ketan_ATA will be kind enough to post the solution.
2 Likes
@Leonidas Thank you very much! 
I am posting code snippet here:
var Follow = pc.createScript('follow');
Follow.prototype.initialize = function() {
this.camOrthoHeight = 6;
this.entity.camera.orthoHeight = this.camOrthoHeight;
this.orthoAnimationSpeed = 5;
this.currentOrthoHeight = this.entity.camera.orthoHeight;
this.targetOrthoHeight = this.entity.camera.orthoHeight;
};
Follow.prototype.postUpdate = function(dt) {
this.targetOrthoHeight = pc.math.clamp(this.camOrthoHeight + (Math.abs(speed)/50), 6, 9) ;
this.currentOrthoHeight = pc.math.lerp(this.currentOrthoHeight, this.targetOrthoHeight, this.orthoAnimationSpeed * dt);
this.entity.camera.orthoHeight = this.currentOrthoHeight;
};
2 Likes