Jump to content

Explosions


GarlicWaffle
 Share

Recommended Posts

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. :)  

Link to comment
Share on other sites

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)

 

  • Upvote 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...