Referencing scripts and components from other scripts

Hi I want to Understand the logic of how I find components inside needle I read the document but I can’t understand
like in Three.js I use this ‘three/examples/jsm/controls/OrbitControls’; how I have to get these from needle

Original Post on Discord

by user 274576156684976128

Hey!
Could you make an example of what you try to do?

You can use any other npm module / package just like before - so your importing three/examples/jsm/controls/OrbitControl from three examples in one of your typescript scripts will still work just the same.

If you have a different dependency (say you want to use another npm package) you can install it to the package.json and then import from your scripts

oh ok tnx

by user 274576156684976128

We do that internally too :slightly_smiling_face:

For example our OrbitControls component does also import the three OrbitControls code.

import { Behaviour, GameObject } from "./Component";
import { Camera } from "./Camera";
import { OrbitControls as ThreeOrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { LookAtConstraint } from "./LookAtConstraint";
import * as THREE from "three";
import { getWorldPosition } from "../engine/engine_three_utils";
import { RaycastOptions } from "../engine/engine_physics";
import { serializeable } from "../engine/engine_serialization_decorator";

export class OrbitControls extends Behaviour {

...

you can have a look at all our implementations as a reference by clicking on the blue link here (just note that changes to that code will not be persistent - but it might help in learning :slightly_smiling_face: )
unknown.png

I little bit confused I worked with three.js to make the game I want to try to make the same thing here
for example, I used camera.position I’m my three.js but here I get the camera but don’t return position value

by user 274576156684976128

Can you show a code example?

public _cameraObject: THREE.Object3D
camera : Camera;

by user 274576156684976128

this.camera= this.context.mainCameraComponent;
this.offset=0;
_cameraObject=this.camera;

by user 274576156684976128

I checked Orbital camera

by user 274576156684976128

Ah you are accessing the camera component - thats not the threejs camera object. You can either use “this.context.mainCamera” or “this.context.mainCameraComponent.gameObject”

When you deal with components the threejs object is always the “.gameObject”

I want to make a third person controller do you have any reference I can use

by user 274576156684976128

Changed the channel name: Referencing scripts and components from other scripts

sorry again

by user 274576156684976128

this.rotateQuarternion.setFromAxisAngle(this.rotateAngle, angleYCameraDirection + this.offset)
this.gameObject.quaternion.rotateTowards(this.rotateQuarternion, 0.2)

by user 274576156684976128

this is what im using for quaternion

by user 274576156684976128

rotateQurternion : Quaternion this is how I define it

by user 274576156684976128

import { Vector3, Quaternion } from “three”

by user 274576156684976128