Can't make particles in explosion collide? :(

Feb 19, 2011 at 4:26 AM

I've tried to add a physics behavior to the path in the explosion behavior and when the explosion occurs it plays the story board and the particles fly out but they don't collide with anything.

I've also tried to add the explosion code from the farseer physics testbed and I have been able to get it to fire but the queryaabb code returns nothing everytime. I'm very confused here.  I'm passing _physicsController.Simulator for the world.

Any idea on how to get either to work? Ideally, I'd like both to work but would apprieciate any help with either.

Thanks!

Feb 24, 2011 at 8:42 PM

Still stuck. Still frustrated. Sigh...

Mar 26, 2011 at 2:45 PM

Still looking for an answer. Is there any way to make the physicshelper explosion work like the farseer physics explosion or to make the particles from the physicshelper explosion collide with other objects?

 

Thanks!

Jun 6, 2011 at 5:01 PM

Yes. I request this answer to this question too. 

 

Thanks.

Jun 6, 2011 at 5:40 PM

So, after i saw a source code, i have contribution to add ObjectBehavior for ucExplode . And i want to contribute to give facility to customize a explode shapes in an exlpode behavior.

Coordinator
Jun 6, 2011 at 6:52 PM

That's great Shersh! - if you want to send me a direct message with the source code, I could integrate for the next build.

Dec 12, 2011 at 1:52 AM

Did this ever end up happening? 

Coordinator
Dec 12, 2011 at 1:47 PM

No, I don't think Shersh ever forwarded his behavior code to me. (Shersh, if you did, please let me know and forward again).

Jan 16, 2012 at 10:53 AM

I added this for my game 'Apple Bin'. You can see the exploding crates in action here: http://youtu.be/raE4YuaHupA 

I used a customised collision event instead of a behavior (haven't had to much experience creating them). It gets all objects inside a bounding box and a applies a force to each which inversely proportionate to the distance from the explosion.  

        public override void CollisionActions(PhysicsSprite sprite1, PhysicsSprite sprite2, PhysicsControllerMain physicsController, SoundManager soundManager)
        {
            if (sprite1.Name.Contains("TNT") && sprite2.Name.Contains("AppleBody"))
            {
                if (Math.Abs(sprite2.BodyObject.LinearVelocity.X) > 1 || Math.Abs(sprite2.BodyObject.LinearVelocity.Y) > 1)
                {
                    if (physicsController.PhysicsObjects.ContainsKey(sprite1.Name))
                    {

                        Vector2 cursorPos = sprite1.Position;

                        Vector2 min = cursorPos - new Vector2(boxSize, boxSize);
                        Vector2 max = cursorPos + new Vector2(boxSize, boxSize);

                        foreach (var physicsObjects in physicsController.PhysicsObjects)
                        {
                            if (!physicsObjects.Value.BodyObject.IsStatic && physicsObjects.Key != sprite1.Name)
                            {
                                //Get a bounding box around where the collision occured
                                Vector2 screenBodyPosition = physicsController.WorldToScreen(physicsObjects.Value.BodyObject.Position);
                                if (screenBodyPosition.X < max.X &&
                                    screenBodyPosition.X > min.X &&
                                    screenBodyPosition.Y < max.Y &&
                                    screenBodyPosition.Y > min.Y)
                                {
                                    //Apply a propotionate force to the elements inside the bounding box
                                    Vector2 fv = screenBodyPosition - cursorPos;
                                    fv.Normalize();
                                    fv *= 0.2f;
                                    physicsObjects.Value.BodyObject.ApplyLinearImpulse(ref fv);

                                    //Start a story board in that position
                                    var explodingObject = sprite1.uiElement as System.Windows.Shapes.Rectangle;
                                    if (explodingObject != null)
                                    {

                                        double left =
                                            physicsController.PhysicsObjects[sprite1.Name].Position.X;
                                        double top =
                                            physicsController.PhysicsObjects[sprite1.Name].Position.Y;

                                        if (
                                            PhysicsControllerMain.ParentCanvas.Children.IndexOf(
                                                _particles) < 0)
                                            PhysicsControllerMain.ParentCanvas.Children.Add(_particles);

                                        _particles.Visibility = Visibility.Visible;
                                        _particles.SetValue(Canvas.LeftProperty,
                                                            left - explodingObject.ActualWidth / 2);
                                        _particles.SetValue(Canvas.TopProperty,
                                                            top - explodingObject.ActualHeight / 2);

                                        _particles.sbExplode.Completed +=
                                            new EventHandler(sbExplode_Completed);
                                        _particles.sbExplode.Begin();
                                        soundManager.PlaySound(SoundManager.SoundList.CrateExplode);
                                    }
                                }
                            }

                        }
                        physicsController.DeletePhysicsObject(sprite1.Name);
                    }
                }
            }

        }