Orbit Controls Script Problem After Update

Hi… for quite a while I’ve been successfully using a brilliant Orbit Controls script that was kindly shared on this forum by @ROBYER1 (I’ve attached it here for ref).

The script has been working fine with a scene I’ve recently been building which was running on Needle 2.67.11-pre. However, earlier today I updated to Needle 3.2.0-exp and the orbit script suddenly stopped functioning. I further updated to Needle 3.2.1-exp this afternoon but it hasn’t altered the fact that the orbit script still isn’t functioning. Nothing else in the project has changed other the Needle updates… and if I open a backup/archive copy of the project that’s still on 2.67.11-pre then the orbit script runs as expected.

ADDITIONAL INFO
I’m on Mac OS Ventura 13.3.1

If anyone has any thoughts on what might have happened and what the solution might be, I’d be very grateful :slightly_smiling_face: Thanks in advance!
ObitControlsEpm.ts

Original Post on Discord

by user 908977119781060648

Hi Frannie, the imports need to be updated.

Try changing them to:

import { Behaviour, GameObject } from "@needle-tools/engine";
import { Camera } from "@needle-tools/engine";
import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { LookAtConstraint } from "@needle-tools/engine";
import * as THREE from "three";
import { getWorldPosition } from "@needle-tools/engine/src/engine/engine_three_utils";
import { Physics, RaycastOptions } from "@needle-tools/engine";
import { serializeable } from "@needle-tools/engine";

Ooooooo, right… cheers for that. I’ll give that a go right now and shout back here with results!

by user 908977119781060648

@marcel :cactus: no joy unfortunately.

When I try and play the preview I get a black screen with this error note in the top right hand corner.

by user 908977119781060648

then try reverting that back to import { Physics, RaycastOptions } from "@needle-tools/engine/src/engine/engine_physics";

not sure why Physics is imported tho, I dont think that makes sense

Will try that. Two tics…

by user 908977119781060648

Nope… it really doesn’t like that, at all. The preview now runs but the scene content jumps around wildly and in a frenzied manner in the browser window :eyes: :grimacing:

I’m sorry but I have to dash off just for now. I’ll be able to have another look at it all in the morning :slightly_smiling_face:

by user 908977119781060648

I would compare it to the normal Needle Orbit Controls script in the samples to see what changed

by user 103054507105067008

Good idea!!! :thought_balloon: Thanks for that suggestion @ROBYER1, I’ll give it a look first thing tomorrow :+1:

by user 908977119781060648

Quick update.

Yesterday, having rebuilt the project as-new from scratch (twice) and having tried a number of other things without any success, I came at the problem again this morning with a fairly heavy heart.

However! I’ve just this minute opened the project up and before doing anything to the scripting I updated from Needle 3.2.1-exp to 3.2.2-exp and the whole thing worked straight away. i.e. @ROBYER1’s original script (unedited and as attached in the OP) works absolutely perfectly once again.

So, while I would unquestionably love to know (and understand!) more about what just happened, and why it’s all okay again, I’m happy to instead just take the win where I find it :grinning:

by user 908977119781060648

PS: I’ve also just now updated to 3.2.3-exp and everything’s working fine with that, too :partying_face:

by user 908977119781060648

Has physics been abstracted!?

by user 300386587278049291

no but physics and all the methods are available via this.context.physics

and there should not be a reason (at least right now) for a component to import the physics class and create a new instance of it (cant imagine a reason for OrbitControls to do that)

Ah ok. I was very excited for a moment :grin: sorry to hijack this thread!

by user 300386587278049291

I want to try tree shaking physics (or make them lazily load) at some point too to reduce the overall engine size (1mb in the bundle is the rapier engine)