physics - impulse on objects within radius

0 favourites
  • 8 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • 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.

  • On bomb clicked

    For each crate

    compare two variables: distance(bomb.x,bomb.y,crate.x,crate.y ) < bomb.radius

    ---> apply force ....

  • 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:

    scirra.com/forum/physics-explosion-with-impact_topic45047.html

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 ^^

  • 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.

  • 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:

    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:

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

    where "bombForce" is a variable that can be adjusted to suit your needs (I used 250). Works a treat!

  • thatjoshguy Nice method, it works for me. But I think the variable needs a large value for a big impulse.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)