How to rotate object to side which look camera ?
class ThirdPersonCamera extends Camera {
boot(domElement) {
this.cameraManager = new CameraManager(domElement);
}
tick(target = null) {
if (target !== null) {
this.cameraManager.target.applyMatrix4(target.matrixWorld);
this.cameraManager.target.set(target.position.x, target.position.y + 2, target.position.z);
}
let targetX = this.cameraManager.target.x;
let targetY = this.cameraManager.target.y;
let targetZ = this.cameraManager.target.z;
let radius = this.cameraManager.radius;
let theta = this.cameraManager.theta;
let phi = this.cameraManager.phi;
let posX = targetX + radius * Math.sin(theta * Math.PI / 360) * Math.cos(phi * Math.PI / 360);
let posY = targetY + radius * Math.sin(phi * Math.PI / 360);
let posZ = targetZ + radius * Math.cos(theta * Math.PI / 360) * Math.cos(phi * Math.PI / 360);
this.position.set(posX, posY, posZ);
this.lookAt(this.cameraManager.target);
}
}
in function tick - target is my object http://joxi.net/bmoYbaBIxVNM8A
And this is my CameraManager:
class CameraManager extends Manager {
implements() {
this.sensitivity = new Vector2(1, 1);
this.target = new Vector3();
this.character = {};
this.radius = 15;
this.theta = 0;
this.phi = 0;
}
realised(deltaX, deltaY) {
this.theta -= deltaX * this.sensitivity.x;
this.theta %= 720;
this.phi += deltaY * this.sensitivity.y;
this.phi = Math.min(170, Math.max(-170, this.phi));
}
event() {
this.boundLockedPointer = () => this.domElement.requestPointerLock();
this.boundMouseMove = event => this.realised(event.movementX, event.movementY);
this.domElement.addEventListener('mousedown', this.boundLockedPointer, false);
this.domElement.addEventListener('mousemove', this.boundMouseMove, false);
}
}
When i move mouse my camera just rotate around my object, but i wanna make rotate object with camera only by axes Y
How i can get it? Thank you