Download Construct 2 release 36

Discussion and feedback on Construct 2

Post » Thu May 26, 2011 2:13 am

Just to toss up ideas, how much power would circular collision take?
B
51
S
10
G
7
Posts: 184
Reputation: 6,825

Post » Thu May 26, 2011 5:03 am

You can implement circular collision yourself just by checking the distance to an object.
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

Post » Thu May 26, 2011 10:59 am

Speaking of which, while distance is a good expression to have, I realized that having a "check distance" condition would also be extremely useful, as you won't have to allocate a private/instance variable in order perform a simple distance check.

Don't know why objects don't already have it, really.
B
94
S
37
G
11
Posts: 404
Reputation: 11,275

Post » Thu May 26, 2011 3:33 pm

They sort of do. Use pick by comparison: distance(.x, .y, otherobject.x, otherobject.y) is less than however many pixels.
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Thu May 26, 2011 3:49 pm

Ah. I forgot that condition could be used like that. STUPID STUPID DUMB. XD

Still, it couldn't hurt.
B
94
S
37
G
11
Posts: 404
Reputation: 11,275

Post » Thu May 26, 2011 6:52 pm

Distance is close, but not exact. Using distance alone would only work with a perfect circle (I was also somewhat inquiring about oval shapes), and would only work with other objects that you wanted point collision or perfect circle collision (Compensating with the other objects circle radius). What if you had a ball and a box?. Plus, the formulas would thrown off entirely if the option to change an objects hot spot is added.
B
51
S
10
G
7
Posts: 184
Reputation: 6,825

Post » Fri May 27, 2011 5:50 pm

Okay, I just discovered that you can't access an object's ID through expressions. THAT would a good idea to implement. Unless I'm somehow missing something.
B
94
S
37
G
11
Posts: 404
Reputation: 11,275

Post » Fri May 27, 2011 6:48 pm

[quote="Candescence":18r8w02e]Okay, I just discovered that you can't access an object's ID through expressions. THAT would a good idea to implement. Unless I'm somehow missing something.[/quote:18r8w02e]

Might try instance count ie sprite(index).
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sat May 28, 2011 1:37 pm

Oh, crap, I think I discovered a bug with the distance expression - mostly to do with picking.

Simply put, I tried a little test with placeable turrets, all of which have a range, which is calculated using the distance expression... Unfortunately, when using the "compare two values" condition, I couldn't get the turrets to fire, period. I messed about with the condition, and discovered that it only worked with the "greater or equal" sign, but then I also noticed that, when I tried to debug the output value for the distance expression, the first one to print was a number that was way too big to be possible. And then I realized that I kept the original instance of the turret object outside the layout - I brought it in, and did more tests, and I realised what the problem was.

Simply put, the "distance" expression plus the "compare two values" condition will ONLY work if the original instances of the two objects are involved - once the TestEnemy gets outside the TestTurret's range, all turrets will cease firing, even if it's in range of the other turrets, or there are other instances of TestEnemy in the original TestTurret's range.

Example cap (click on the black stuff to spawn turrets)
B
94
S
37
G
11
Posts: 404
Reputation: 11,275

Post » Sat May 28, 2011 1:53 pm

@Candescence, that's not a bug, it's by design since Construct Classic.

The Compare Values condition does not do any picking. It literally works out two numbers and compares them.

It has no idea what you're trying to do, so when you write TestEnemy.X, it just gets the first instance's X co-ordinate, and only ever the first instance's X co-ordinate. So you are actually telling Construct to only compare the distance between the first two instances. It's not a bug.

It's really easy to solve: just put a 'For Each TestEnemy' condition above it and it will repeat the distance measurement for each instance!

If you want to support multiple turrets you should add another for each, i.e.:

+ For Each TestTurret
+ For Each TestEnemy
+ distance(TestTurret.X, TestTurret.Y, TestEnemy.X, TestEnemy.Y) < 300
-> Shoot...

This compares the distance between every combination of enemy and turret. However, with lots of objects, this quickly becomes inefficient.

What you need is the turret behavior, in Construct 2 :) In Classic, the Turret behavior takes care of all of this for you, and does it very efficiently as well.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: Ashley and 15 guests