# Need a better touch radius method. Any thoughts?

Get help using Construct 2

### » Wed Mar 13, 2013 7:34 pm

So I'm working on a little mobile game where you have to touch these randomly spawned physics balls. I have a system where there is an invisible box pinned to each ball, and I use that to detect the touch so that it has a larger radius, like so:

When the box is touched, it sets the ball as selected and destroys the box, to prevent it from being touched again. Unfortunately, sometimes when two or more balls are close to each other, you would end up touching multiple boxes, but would only select one ball. This would render the other ball un-touchable.

I probably need to do one of two things:
1. Instead of destroying the box, finding a way to make it un-touchable after it has been selected.
2. Find a different method of detecting a touch within a certain radius of the ball, and getting rid of the box altogether.

What do you guys think? I'd prefer to get rid of the box all together and find a way to detect a touch within a certain radius, but I can't seem to find anything. I may just be overlooking something extremely obvious and wasting my time, but maybe not.

Edit: Actually the first idea on that list wouldn't work either, so I need to figure out something with the second idea. darkpivot2013-03-13 19:39:07
B
19
S
4
G
1
Posts: 42
Reputation: 1,793

### » Thu Mar 14, 2013 9:30 am

I had similar issue with touch affecting multiple objects.

Fixed it by:

On touch myObject
MyObject Pick top Instance

So I only touch one at a time.

Also you can probably get rid of the extra box - you could make a large sprite (e.g. 128x128), draw your ball in the middle, and make sure the collision bounds are set to the full sprite area.silkc22013-03-14 09:32:12
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

### » Thu Mar 14, 2013 7:22 pm

I use:

On touch start
Pick closest object to touch.x, touch.y
Compare value: distance(touch.x, touch.y, object.x, object.y) is less or equal than object.width+200
- set object value 'active' to 0

That way by using a value, no extra objects are needed and your get a perfect circular radius for the touch detection.
Moderator
B
90
S
32
G
33
Posts: 3,005
Reputation: 27,492

### » Thu Mar 14, 2013 7:38 pm

Thank you both! I got it working with silkc2's method, and it works perfectly!
B
19
S
4
G
1
Posts: 42
Reputation: 1,793

### » Sun May 05, 2013 5:40 pm

I had the same problem. The @silkc2 almost worked to me. I am dealing with rectangles instead of circles, so if the player touch the rectangle corners, no event is triggered.
B
229
S
6
G
8
Posts: 86
Reputation: 12,320

### » Tue Jul 29, 2014 6:20 pm

Couldnt you just make the ball sprite bigger?
I mean, just make a larger transparent sprite, and put the ball in the middle of that. And then set to bounding box? or am i missing something?
B
35
S
8
G
7
Posts: 512
Reputation: 7,813