You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{Behaviour,serializable,setWorldPosition}from"@needle-tools/engine";import{Object3D,Vector3}from"three";constvector1=newVector3();constvector2=newVector3();exportclassPointerFollowerextendsBehaviour{
@serializable(Object3D)target?: Object3D;
@serializable()offset: number=10;update(): void{constcam=this.context.mainCamera;constinput=this.context.input;if(!this.target||!cam)return;// get relative mouse position, in range -1 to 1constmouse=input.mousePositionRC;// get world position of mouse on the near planevector1.set(mouse.x,mouse.y,-1).unproject(cam!);// caulculate direction from camera to world mousevector2.copy(vector1).sub(cam.position).normalize();// offset it to the wanted distancevector1.addScaledVector(vector2,this.offset);// apply the resultsetWorldPosition(this.target,vector1);}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
opera_N7KkSO0ozo.mp4
Beta Was this translation helpful? Give feedback.
All reactions