GarlicWaffle Posted June 15, 2017 Share Posted June 15, 2017 I'm making a game that incorporates explosions, and was wondering if there was a way to make the explosion move nearby props to make it more realistic. It would be fun to see things go flying around the room when something explodes. I also just wanted to post a question for the first time. Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted June 15, 2017 Share Posted June 15, 2017 http://steamcommunity.com/sharedfiles/filedetails/?id=932421043 Quote Link to comment Share on other sites More sharing options...
Genebris Posted June 16, 2017 Share Posted June 16, 2017 Apply forces to the them. What exactly do you need help with? Quote Link to comment Share on other sites More sharing options...
Einlander Posted June 17, 2017 Share Posted June 17, 2017 Here is some pseudo-code of how i did it in the explosions workshop item Creates a unit vector pointing in the direction we want to push. Needs to be in the GLOBAL space. force_direction = ( destination_entity:GetPosition(true) - source_entity:GetPosition(true) ):Normalize() Check if object is airborne. If it is, leave it alone. If there is more than one explosion close together, it will cause the entity to no clip since the force will become cumulative. if destination_entity:GetAirborne() == false then force_direction y = 1 else force_direction = Vec3(0) end Push the object while attempting to cancel out the objects gravity. (we multiply by the worlds inverse gravity.). We push in the GLOBAL space. destination_entity:AddForce(force_direction * Vec3((-world:GetGravity().y / destination_entity:GetMass())) * blast_force, true) 1 Quote Link to comment Share on other sites More sharing options...
GarlicWaffle Posted June 17, 2017 Author Share Posted June 17, 2017 Thanks everyone! I knew that I needed to apply forces to the objects somehow, I just had no idea what the easiest way to do it was, or how to start, but that code was super helpful! Thanks Einlander! Now my dream to destroy the player with flying shrapnel can finally come true... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.