How do I modify the Orbit Controls scripts?

Hi! I鈥檓 trying to modify some of the values in the .ts and .js scripts, so that the Orbit Controls work like the Map Controls example (three.js examples), which is basically just that, a modified Orbit Controls script (three.js/examples/misc_controls_map.html at master 路 mrdoob/three.js 路 GitHub). However, the values are not applying when I test the scene, since the CS component keeps its original default values instead of the new ones and there are some variables that I need to modify that are not available in the component, but I鈥檓 not allowed to modify the component鈥檚 script itself to add them. Any tips?

Original Post on Discord

by user 239022618240483330

Hello, there are a few ways to do that with different pros and cons.

one way to go about it would be to just copy the script/component and create your own version based on that.

Another one would be by adding a new c# script and implement AdditionalComonentData - with that you can inject new settings in OrbitControls on Export. In the typescript side you can replace or wrap the methods you want to change (or use the @prefix decorator attribute but thats a bit experimental at this point and undocumented)

Quick example, this is my own copy of the orbit script modified, not the best way to do things I鈥檓 sure but you can do what you want with it from here

by user 103054507105067008

For those who want the finished script, here it is:

by user 224464722878005248


by user 224464722878005248

And thanks to @ROBYER1 for your Script because the original OrbitControl on Needle can鈥檛 disable Rotation.
But I need the OrbitControl to use the LookAtConstraint so it better like it

But what is the 鈥淟ook at constraint 01鈥 with the float number ?

by user 224464722878005248

Hi all鈥 sorry to bother you with such a basic query but I鈥檓 very inexperienced with Unity and I鈥檓 hoping you can steer me in the right direction.

The above solutions seem to be exactly what I鈥檓 looking for (at least I鈥檓 pretty certain they are) but despite spending a couple of days trying to ascertain what I might need to do with them I鈥檝e still no idea how to implement either of the brilliant scripts that you ( @ROBYER1 and @AeistDesmos ) have so kindly provided.

I鈥檓 very happy to learn, so any kind of pointers (a screenshot鈥 or anything like that鈥 indicating where I might need to put stuff) would be very gratefully received鈥 and feverishly studied :sweat_smile: 鈥 at this end.

I hope you or someone can help鈥 but I鈥檒l totally understand if there isn鈥檛 time to do so if this is too much of a newbie question :slightly_smiling_face:

by user 908977119781060648

Hey @frannie :beer: sorry for the late reply. You should be able to just copy paste the scripts from above in a new typescript file in src/scripts for example, a unity component should automatically generate which you can then add to your camera in unity (you might to need restart the server if its running)

I hope i understand your question right. Here is a very short video about scripting

Awesome鈥 huge thanks for this @marcel :cactus:. I鈥檒l have a good try at it :slightly_smiling_face: :+1:

by user 908977119781060648

Okay so that all works鈥 kinda鈥

The good news: the ObitControlsEpm.ts is absolutely perfect for what I was hoping to achieve and I can run things exactly as expected locally.
The bad news: I don鈥檛 seem to be able to compile the script when it comes to building a production version of the project.

What I see is this鈥

by user 908977119781060648

That means that typescript is not installed. Can you try running npm install typescript -g (it will install typescript globally for npm)

Will do鈥 two minutes鈥

by user 908977119781060648

Sorry for the delay鈥 I can鈥檛 get it to work, so I tried lots of refreshes/reboots etc. No joy :anguished:

by user 908977119781060648

I now see this鈥

by user 908977119781060648

Ah I think threejs changed their orbit controls and enableKeys doesnt exist anymore. You need to remove this line (98 i think)

this._controls.enableKeys = this.enableKeys; < this is wrong

Oooooo, right鈥 I鈥檒l give that a go鈥

by user 908977119781060648

Sadly no luck. Now when I run 鈥楴eedle Engine > Export and Build Dist (Production)鈥 I no longer get the 鈥榝ailed to compile script鈥 notification, but the resultant build just displays the loading bar followed by an empty black screen.

The console shows this鈥

by user 908977119781060648

Can you send me the project? I鈥檒l take a look