[SOLVED] Rotate by touching the screen

Did someone do one of these
https://playcanvas.com/editor/scene/733295

using touch?
thanks

Hello @vgupgrade! Based on the project you sent I think you can do something like below.

// Initialize
LookAtMouse.prototype.initialize = function() {
    if (this.app.touch) {
        this.app.touch.on(pc.EVENT_TOUCHSTART, this.onTouchStart, this);
        this.app.touch.on(pc.EVENT_TOUCHMOVE, this.onTouchMove, this);
        this.app.touch.on(pc.EVENT_TOUCHEND, this.onTouchEnd, this);
        this.app.touch.on(pc.EVENT_TOUCHCANCEL, this.onTouchCancel, this);
    }
};
// Touch move
LookAtMouse.prototype.onTouchMove = function(e) {
    this._mousePos.set(e.touches[0].x, e.touches[0].y, 0);
};
1 Like

damn that simple and clean the code, thanks a lot, man, it worked as I needed

Now I just use a device identifier

LookAtMouse.attributes.add(‘mobileOrDesk’, {type: ‘boolean’ …

\ o /

Hey @vgupgrade,

If you need that I suggest to try posting on another topic! :slight_smile:

1 Like

Why do you need that in this case?

a simple bubble-style game that works on desk and mobile

If you add this new touch part to the original mouse script, it will work on both devices, I guess? (The oirginal part on desk and the new part on mobile).

1 Like

Yeahh.
I’m just thinking about the firing mechanics.

OBRIGADO!

No problem, you’re welcome!