If I use the built-in 'Touch' node, it detects touches from all over the screen instead of just detecting the touch on the object the node attached to. Having the object created in UI (in the form of a button) works but it doesn't feel right. Is there any way to limit the touch only to the object through javascript or node?
The code you need can be found in the pool preset. it takes the xy value of the object and gives it a perimeter of pixels. you can make that bigger or smaller in the code.
Hi guys!! im trying to find this option, i am not an avid programmer so i am almost guessing where to find it but, is here where i must edit the code?? let wp = this.scene().screenToWorld(point.x, point.y); ???????????????? if this is so what should i do?
Hi bro. You can refer to this API docs: http://download.buildbox.com/buildb...-component-script-enabletouchswallow-priority Basically, the touchBegan(point) is a built-in function that will detect user touch on the screen. The function will receive the location of the click via point parameter. Inside this function, you then need to add a check to see if the point variable is at the same position with the object that you want the touch to be detected. However, the point variable and object position uses 2 different unit so you need to convert them and then measure the distance. You can do something like this: Code: function touchBegan( point ){ let _startPoint = point; let hitbox_size = 0.5; var wp = this.scene().screenToWorld(_startPoint.x, _startPoint.y); wp = new Vec3(wp.x, wp.y, wp.z); pos = new Vec3(pos.x, pos.y, pos.z); // Example if you are measuring in the Y axis. Change accordingly if((wp.y-pos.y<= hitbox_size) && (wp.y-pos.y>= -hitbox_size)){ log("Touched!") this.emitSignal('Touch', true); } } component.touchBegan = touchBegan;