Activate and deactivate object on mobile detection

I see, i presume both scripts are on the camera gameobject?

nope the world game obbject, the worls is rotating

by user 546555823451668481

`import { Behaviour, isMobileDevice } from “@needle-tools/engine”;

export class RotateObject extends Behaviour {
private isMouseDown: boolean = false;
private mouseStartX: 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;

awake() {
this.enabled = !isMobileDevice(); // Disable the script if it’s opened on a mobile device
if (!this.enabled) return;
// Rest of the awake implementation

start() {
window.addEventListener(“mousedown”, this.onMouseDown.bind(this));
window.addEventListener(“mousemove”, this.onMouseMove.bind(this));
window.addEventListener(“mouseup”, this.onMouseUp.bind(this));

update() {
this.timeElapsed += this.context.time.deltaTime;

if (this.isMouseDown && this.timeElapsed >= this.startDelay) {
  const mouseDeltaX = this.context.input.mousePosition.x - this.mouseStartX;
  this.targetRotation = this.initialRotation + mouseDeltaX * this.rotationSpeed;

// Smoothly rotate towards the target rotation
const currentRotation = this.gameObject.rotation.y;
const newRotation = this.lerp(
  this.smoothness * this.context.time.deltaTime
this.gameObject.rotation.y = newRotation;


onMouseDown(event: MouseEvent) {
if (event.button === 0) {
this.isMouseDown = true;
this.mouseStartX = this.context.input.mousePosition.x;
this.initialRotation = this.gameObject.rotation.y;

onMouseMove() {
if (this.isMouseDown) {
// No need for any action here

onMouseUp(event: MouseEvent) {
if (event.button === 0) {
this.isMouseDown = false;

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

I think this fixed the issue, i think this is disabling the mouse script after it is checking the mobile device

by user 546555823451668481

For simpler code sharing, you can drop the .ts file right into discord and it will make a nice preview :+1:

I see you had to wrap everything int to ` ` :grimacing:

hahaha yeah

by user 546555823451668481


by user 546555823451668481

can you please confirm if this is diabling the script on mobile device detection ?

by user 546555823451668481

presumably yes :+1:
this.enabled = !isMobileDevice();

you negate the result of isMobile so it works as isDesktop and thus the script is only enabled on desktop.

awake happens right when the object is created, the start should happen later and it is most probably conditioned by the enabled that we’ve set before. So it all should work.

But obviously you have the project in front of you, so please test it :slight_smile: You can open your local build on mobile as well if you don’t have a restricted network. Or you can deploy to glitch :+1:

yes it works perfectly right now

the only issue i find is that it has video players in it showing animated small video clips, but 99% of the time the video will not play on the mobile device

by user 546555823451668481

videos can be odd, since you need to first interact / click on the page to be able to start a video. It is recommended to add a “welcome” screen that forces you to click on something.

so the video is inside a small art frame, and the art appears when the gizmos gets triggered

by user 546555823451668481

and there are many like this

by user 546555823451668481

So you’re saying that the user interacts with the page before the video is played?

Can you deploy to glitch or show me more about the app? I’m bit unsure what is the concept here.

ya wait

by user 546555823451668481

please open it on the mobile, and in the website go to the art section there you will find the video player, right mow there is only one.

also check if rotation is happening smoothly on your side on mobile or you find some glitch

by user 546555823451668481

What a cute scene :slight_smile:

Really cute :slightly_smiling_face:

haha thanks :slightly_smiling_face:

by user 546555823451668481

Hm, so it doesn’t want to play the video with these warns in the console

(Android - Samsung s9+ - a bit older android at this point)