Mobile touch control

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*
    const eventData = event as unknown as PointerEventData;
    if (eventData && eventData.pointerId === 0) {
      this.isPointerDown = true;
      const pointerPosition = this.context.input.getPointerPosition(0);
      if (pointerPosition) {
        this.pointerStartX = pointerPosition.x;
        this.initialRotation = this.gameObject.rotation.y;
      }
    }
  }

  onPointerMove(event: Event) {
    const eventData = event as unknown as PointerEventData;
    if (this.isPointerDown && eventData) {
      // No need for any action here
    }
  }

  onPointerUp(event: Event) {
    const eventData = event as unknown as PointerEventData;
    if (eventData && eventData.pointerId === 0) {
      this.isPointerDown = false;
    }
  }

  private lerp(a: number, b: number, t: number): number {
    return (1 - t) * a + t * b;
  }
}```

*by user 546555823451668481*

anyone ?

by user 546555823451668481

You mean you drag from outside the screen?

if screen is splitted in numbers between -5 to 5 where -f is extreme left and 5 is extreme right of screen, then the the drag only happens at -1 to 1 portion of the screen, outside that zone the drag is not detected(and this only happens at upper half of the screen , the lower half detects the drag and touch

by user 546555823451668481

Can you record a video? Input is only forwarded if it starts on the 3d element right now.

oh thats why, because i have 3D element only in lower half of the screen

by user 546555823451668481

Does that solve your issue? :slightly_smiling_face: