Skip to main content

TouchInput

The TouchInput class provides methods to capture and manage touch input from devices like smartphones and tablets.

start()

Starts capturing touch input.

Example:

Input.touch.start();

stop()

Stops capturing touch input by removing all event listeners.

Example:

Input.touch.stop();

count(): number

Returns the number of active touch points currently being tracked.

Example:

const activeTouches = Input.touch.count();
console.log(activeTouches);

touches(touchIndex?: number): TouchEventX | TouchEventX[]

Returns either all active touch points or a specific one by index.

Example:

const firstTouch = Input.touch.touches(0);
const allTouches = Input.touch.touches();

raycast(camera: THREE.Camera, touchIndex?: number): RaycastOutput

Projects a touch point into 3D space by converting screen coordinates into a ray using the camera and renderer.

Example:

const ray = Input.touch.raycast(camera, 0);
console.log(ray.raycaster, ray.position);

isSupported(): boolean

Checks if the device supports touch input.

Example:

if (Input.touch.isSupported()) {
console.log('Touch input is supported');
}