I have this script where when i click at the center zone of the screen and drag then the rotation happens, but when i click and drag from left/right of the screen and drag then the rotation does not happen and i think its because the touch is not detected at left/right of the screen, how can i fix this ?
export class RotateObjectPointer extends Behaviour {
private isPointerDown: boolean = false;
private pointerStartX: number = 0;
private initialRotation: number = 0;
private targetRotation: number = 0;
public rotationSpeed: number = 1; // Default rotation speed is 1
public smoothness: number = 5; // Smoothness factor, adjust as needed
public startDelay: number = 3; // Delay in seconds before rotation starts
private timeElapsed: number = 0;
start() {
this.context.input.addEventListener(InputEvents.PointerDown, this.onPointerDown.bind(this));
this.context.input.addEventListener(InputEvents.PointerMove, this.onPointerMove.bind(this));
this.context.input.addEventListener(InputEvents.PointerUp, this.onPointerUp.bind(this));
}
update() {
this.timeElapsed += this.context.time.deltaTime;
if (this.isPointerDown && this.timeElapsed >= this.startDelay) {
const pointerPosition = this.context.input.getPointerPosition(0);
if (pointerPosition) {
const pointerDeltaX = pointerPosition.x - this.pointerStartX;
this.targetRotation = this.initialRotation + pointerDeltaX * this.rotationSpeed;
}
}
// Smoothly rotate towards the target rotation
const currentRotation = this.gameObject.rotation.y;
const newRotation = this.lerp(
currentRotation,
this.targetRotation,
this.smoothness * this.context.time.deltaTime
);
this.gameObject.rotation.y = newRotation;
}```
[Original Post on Discord](https://discord.com/channels/717429793926283276/1125040665504522240)
*by user 546555823451668481*