Unity - Set azimuthal/polar angle of OrbitControls

In Needle we can get azimuthal/polar angle of OrbitControls, but can’t set azimuthal/polar angle. We also logged OrbitControls object in console and couldn’t find these methods. (please see images below)

Raw three.js has setAzimutalAngle method, but seems like Needle doesn’t. How can we achieve it (setting angles) ?

Our target is extend orbital movement of camera, so camera should be snapped to cube side, which is closer to viewport


Original Post on Discord

by user 267660755443122181

You can always access the underlying three.js OrbitControls with .controls and use the methods from that

yes, as I said we can use getAzimuthalAngle, but there are no setAzimuthalAngle method

by user 267660755443122181

As felix said: you can access the underlying OrbitControls (from three.js) to set the value via orbitControls.controls.setAzimuthalAngle
image.png

when I call setAzimuthalAngle an error occures. What I am missing? getAzimuth works btw


image.png

by user 267660755443122181

it is probable that the c var is null. That would mean the way how you get OrbitControls is not working.
Can you check that?

You can also make that as a reference that you can set via unity.

@serializable(OrbitControls)
controls?: OrbitControls;

That will make a normal unity reference field in the inspector where you can drag and drop your camera (the orbital controls component on it)
image.png

the correct code would be this.context.mainCameraComponent.gameObject.getComponent(OrbitControls)
note that you dont insert a string but the type that you want - it is (OrbitControls) and NOT ('OrbitControls') when getting a component

alternatively you can also use GameObject.findObjectOfType(OrbitControls) if you want to search it in the whole scene (it’s ok if you do that once, you shouldnt query for it every frame for example)

c is not null. because getAzimuth and getPolar logs works

by user 267660755443122181

(‘OrbitControls’) also works in my case. I am curious why setAzimuthAngle method is not defined here. But in raw three.js it can be used

by user 267660755443122181

It may break in a production build tho - I wouldnt recommend it and we might remove this in a future release

Thanks, noted.
Any idea on issue? In the uploaded image there are no set methods for azimuth/polar angle?

by user 267660755443122181

Are you looking for these? three.js docs I’m not sure if you can set it directly

where did you get that info from that three.js has a setter for it? I dont see that

Another developer has sent me this image and there are two set methods in logs. He also uses three.js and setAzimuth works in his case.

by user 267660755443122181

Which version of three.js did he use? The current three.js doesnt have such a method

I believe the above script is from the pmndrs/three-stdlib OrbitControls

(not from the one built into three.js, which we’re using)

You can totally install three-stdlib to your project and use that if you feel more comfortable with that (you can wrap it in a small Behaviour and apply that to your camera instead of our core OrbitControls behaviour)