[SOLVED] How to set orthoHeight of an orthographic camera?

Hi, to change the orthoHeight value of a orthographic camera I do this:

var Camera = pc.createScript('camera');

Camera.prototype.zoom = function(value) {
    alert('zoom');
    this.orthoHeight = 2.0;
}

// initialize code called once per entity
Camera.prototype.initialize = function() {

};

// update code called every frame
Camera.prototype.update = function(dt) {

};

But when calling the zoom function, the alert will show, but orthoHeight does not change.
What am I doing wrong?

Hi @simmania,

Right now you are setting the orthoHeight property on the camera script, not on the camera component.

Try this instead:

this.entity.camera.orthoHeight = 2.0;
1 Like

No, doesn’t work.

Is the script attached on an entity with a camera component?

Try sharing some more context on what exactly doesn’t work, and if possible a sample project.

Yes I have a Camera entity with a Camera component. And the script above is attached to this camera.
Then I call the zoom() function after a while. I know that it is called because the alert(‘zoom’) works.

This is the camera entity


orthoHeight is set to 4 in the editor. When I fill in 2 in the editor I get a zoom effect. I want this same effect using a script.

Can you share your zoom() method and how/where you call it?

I found the problem.

I’m confused now, because I tried again:

this.entity.camera.orthoHeight = 2.0;

And now it works!

Don’t know what went wrong before. Sorry for that.

1 Like