physics - impulse on objects within radius

Get help using Construct 2

Post » Mon Aug 06, 2012 10:10 pm

Hi,

Been playing around with Construct 2 for a couple of days now - very impressive.

I'd like any suggestions / links on how to do this:

2 Objects with Physics: Bomb, Crate->Bounding Box

In the scene there is 1 Bomb and several Crates.

I can click the Bomb and apply an impulse.
But it seems to apply the impulse equally to all instances of Crate, regardless of their position.

I'd like to check the position of each Crate instance relative to the Bomb and then decide whether to apply an impulse to that Crate instance.

Pretty straightforward to do in JS or AS3:
Loop thru an array of Crate instances, get the current X,Y of each instance, compare it to Bomb X,Y, and make a decision.

How would you accomplish this within the Event Sheet?

Or is there a way to inject and call a custom function ?

Thx.

sam3d2012-08-06 22:18:53
B
7
S
1
Posts: 11
Reputation: 929

Post » Tue Aug 07, 2012 6:35 am

On bomb clicked
For each crate
compare two variables: distance(bomb.x,bomb.y,crate.x,crate.y ) < bomb.radius

---> apply force ....keepee2012-08-07 06:36:38
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Wed Aug 08, 2012 2:06 pm

keepee - yes, I know how to use distance. I was asking about how to use it and arrays within the context of the Event Sheet. But thanks.

I found this, which I don't quite understand yet re Event Sheet, but it is a good starting point:
http://www.scirra.com/forum/physics-explosion-with-impact_topic45047.html
B
7
S
1
Posts: 11
Reputation: 929

Post » Wed Aug 08, 2012 3:54 pm

Why do you want to use an array? The "For each object" loop @keepee mentioned should do the trick. It will loop through all the instances and apply the action only to the objects that meet the conditions.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Aug 08, 2012 4:53 pm

I prefer to use a mask around the bomb and check if it's colliding with the object, the mask can be pinned to the bomb and still invisible.

The bounciness and density will make the rest ^^
ImageImageImageImageImageImage
B
93
S
20
G
14
Posts: 1,218
Reputation: 19,500

Post » Wed Aug 08, 2012 6:24 pm

Nimtrix - yes, the For Each loop is what I wanted (duh).

Telles0808 - you prefer a mask because it allows for fewer calculations via collide as opposed to relative distance ?
I need the latter as I don't want to rely on collision, but was wondering.

I have an example working using keepee's suggestion...

Thx for the replies - very helpful in getting oriented. sam3d2012-08-10 14:06:23
B
7
S
1
Posts: 11
Reputation: 929

Post » Thu Nov 01, 2012 12:47 pm

Hate to revive an old thread, but as I was looking to do the same thing this may help others:

I found simple way to do this based on the discussion in this thread:
http://www.scirra.com/forum/black-hole-physics_topic41431.html


I simply added a click event on my "bomb", with an "apply impulse towards position" action on my crates using this formula:

[code]
Impulse: -bombForce/distance(bomb.X,bomb.Y,crate.X,crate.y)^2
X: bomb.X
Y: bomb.Y
Image point: 0
[/code]

where "bombForce" is a variable that can be adjusted to suit your needs (I used 250). Works a treat!
B
8
Posts: 32
Reputation: 1,039

Post » Sat Jul 13, 2013 5:15 am

@thatjoshguy Nice method, it works for me. But I think the variable needs a large value for a big impulse.tetriser0162013-07-13 05:17:12
Banned User
B
15
S
3
G
3
Posts: 74
Reputation: 3,070


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests