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

Get help using Construct 2

Post » Wed Sep 24, 2014 10:30 pm

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
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 7
Reputation: 189

Post » Wed Sep 24, 2014 11:34 pm

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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Sep 24, 2014 11:51 pm

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.
B
56
S
15
G
13
Posts: 826
Reputation: 17,705

Post » Thu Sep 25, 2014 12:01 am

Sometimes you can fake it :) But better math would give better results.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Sep 25, 2014 9:30 am

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
B
3
Posts: 7
Reputation: 189

Post » Thu Sep 25, 2014 9:53 am

In my example you would use a For each. For collision, the picking is done for you.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Sep 25, 2014 12:08 pm

@MrBr

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)
Find all the Construct 2 games that were on Steam Greenlight here
B
36
S
10
G
7
Posts: 480
Reputation: 7,025

Post » Thu Sep 25, 2014 12:14 pm

Cough, Line of Sight.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Thu Sep 25, 2014 12:17 pm

OddConfection wrote:@MrBr

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
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Thu Sep 25, 2014 6:20 pm

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

Greetings
B
3
Posts: 7
Reputation: 189


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests