# How do I check if sprite is within radius of another one

0 favourites
• 10 posts
From the Asset Store
Footsteps SFX One contains 400 sounds of steps and jumps on different surfaces.
• Hi everyone

I'm new to C2 and trying to get a small project running in the free version. I've come to a point, where i need to detect if a moving object is within a radius around a static object. on the image attached (ex.png) i've painted a little example to understand.

the green ball is moving along the path (black). as soon as it gets within the radius of the blue square (red circle) it should change its path towards the square.

my first approach was to do it with "is overlapping at offset" event condition, but that one needs a specific offset and i want it to be a radius. next i tried to achieve this with the angle operations but i kinda dont get them right.

is there an existing solution for my problem that i just dont see? or has anyone done something like this or can give me some hits? would appreciate any feedback!

thx a lot

• [quote:1tb1kho7]as soon as it gets within the radius of the blue square (red circle) it should change its path towards the square.

There's your answer? i.e. use math not collisions.

• The correct way would be to use Math, which I have no idea how to do. The other temporary would be to pin a transparent object to your Sqaure. Then set the transparent objects collision edges in a circle.

• Sometimes you can fake it But better math would give better results.

• Thx for the quick answers and the example

Now there's an other problem: i dont know how to handle the behaviour only for a single instance. if i change the path it will be applied for all instances of the object type. but i only want it to be for the instance within that radius. is there a good guide on handling instances on the event conditions? to what i found out it seems not to be likely to do so.

as a first & simpler attempt ill be trying it with Tekniko's idea, witch seems pretty easy and straight forward but if you know about the instance handling in event conditions please let me know where i can get better/deeper understanding.

thx a lot

• In my example you would use a For each. For collision, the picking is done for you.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I've not checked the capx codah posted, but I'm assuming you'd just want something like:

Event: For each Ball

SubEvent: distance(Ball.X, Ball.Y, Square.X, Square.Y) <= Radius

Action: Ball set angle to angle(Ball.X, Ball.Y, Square.X, Square.Y)

• Cough, Line of Sight.

• I've not checked the capx codah posted, but I'm assuming you'd just want something like:

Event: For each Ball

SubEvent: distance(Ball.X, Ball.Y, Square.X, Square.Y) <= Radius

Action: Ball set angle to angle(Ball.X, Ball.Y, Square.X, Square.Y)

The For each ball + compare two values can also be merged with a pick by comparison

• Thank you all very much with the "for each" I got it working just as I wanted to.

Greetings

• 10 posts