When changing camera.up, OrbitControls does not function correctly

Hi,

I want the camera to focus on the target from the specified position when I press the button.

However, when changing camera.up, the rotation behavior of OrbitControls no longer functions correctly.

Is there a solution to this problem?

1 Like

when you change from camera to another you must dispose the old orbit controls and load a new orbit controls for the new camera.

// Load orbit controls
window.loadOrbitControl=function(x,y,z){
	if(engineParameters.orbitControl!=null)engineParameters.orbitControl.dispose()
	engineParameters.orbitControl=new OrbitControls(engineParameters.camera,engineParameters.renderer.domElement)
	engineParameters.orbitControl.enableDamping=true
	engineParameters.orbitControl.maxPolarAngle=Math.PI*.495
	engineParameters.orbitControl.minDistance=1
	engineParameters.orbitControl.target.set(x,y,z)
	if(!isMobile){
		engineParameters.orbitControl.enableZoom=engineParameters.cameraIndex==3
	}else engineParameters.orbitControl.rotateSpeed*=playerParameters.drag.rate
}
1 Like

Rebuilding OrbitControls now works correctly.
Thank you.

But I don’t want to use another camera, I want to move the same camera to a specified position, do I still have to recreate OrbitControls in that case?

You can use single camera but when you switch from first person to third person and orbit the camera is just transfer from one vector to another.

You can do this by creating multiple pivots for camera to lerp to

// Create cameras
window.createCameras=function(c0){
	engineParameters.camera.zoom=1
  engineParameters.cameras=[]
	if(c0)engineParameters.cameraIndex=1
	// Chase camera
	registerCamera(modelsParameters.driveVehicleIndex[playerParameters.index]!=null?.65:.86,modelsParameters.driveVehicleIndex[playerParameters.index]!=null?.5:orientation==0?.5:.86,0,c0)
	// First person camera
  registerCamera(modelsParameters.driveVehicleIndex[playerParameters.index]!=null?.65:.86,modelsParameters.driveVehicleIndex[playerParameters.index]!=null?.15:.015,1,c0)
	// Aerial camera
	registerCamera(orientation==0?.86:1,modelsParameters.driveVehicleIndex[playerParameters.index]!=null?4:orientation==0?1.2:2,2,c0)
	// Orbit camera
	registerCamera(orientation==0?.86:1,modelsParameters.driveVehicleIndex[playerParameters.index]!=null?4:orientation==0?1.2:2,2,c0)
	if(c0){
		setTimeout(function(){
			processMemory.cX0=lsRd('myCamera'+myUserID.uid)==null?playerParameters.camera.select:JSON.parse(lsRd('myCamera'+myUserID.uid)).index
			engineParameters.cameraIndex=processMemory.cX0==3?2:processMemory.cX0
			if(c0)hideMyMesh()
		},900)
	}
}
// Register camera
function registerCamera(ht0,ds0,iC0,c0){
	processMemory.cam=new THREE.Object3D()
	processMemory.cam.position.set(0,playerControlsParameters.height[playerParameters.index]*ht0,-playerControlsParameters.height[playerParameters.index]*ds0)
	if(true){
		playerControlsParameters.player.add(processMemory.cam)
	}else playerControlsParameters.player.children[iC0]=processMemory.cam
	engineParameters.cameras.push(processMemory.cam)
	ht0=ds0=iC0=c0=undefined
}