Touch on tutorial entity picking project?

Hi everyone !

I would like to ask how does it come that on this project :

It works with mouse click and also with touch as I use the same code (raycast one) on my project :

to change the color of the sofa but it works only on computer not with touch.
I tried to add this :
if (app.touch) {
app.touch.on(“touchstart”, this.onSelect, this);

But I think it’s not enough

Thanks in advance,

I am not very clear on what I would like to do.
I would like to make my raycast working on touch on object and also with click (click is already working here).

Thanks a lot,


So I have a way of doing this I made myself, though I kind of use a hollow script object to help handle the event after the touch, but the script can be as follows in this link

In short

      //normalize touchscreen and mouse events
      _onTouchStart: function (e) { 
        //self reference for loop
        var self = this;
        e.changedTouches.forEach(function(i) {
            self._onDown(i.x, i.y, i);
      _onMouseDown: function (e) {
        // respond to event
        this._onDown(e.x, e.y, e);

This allows you to catch both touch and mouse, break out the x and y locations and pass the touch/mouse instance itself to the single function. From there you can treat it the same way for both, additionally checking if the id property exists to identify a touch.

PS: I started writing this for exactly the same idea. You can see this in action here

1 Like

Thanks a lot I will look into that ! :slight_smile: