I'm using a game engine that has a ton of physics stuff built in. What I am currently trying to do is to simulation an explosion with F force in an x,y coordinate system and figure out how other items in the world are affected by it (they each have x,y as well).
The ultimate function I call is applyForce and it takes an x,y vector in Newtons for the force and a point to act on (the other objects in this case).
Currently I am doing the following:
- Determining the distance of the explosion point for each of the objects' x,y coordinates
- If the distance is less than the force F (my total explosion force) then I proceed
- I subtract the distance from F and assign that back to F - so this effectively becomes the total force that can act on the object based on distance
- I find the angle of the explosion point from the object by atan2(x1-x2,y1-y2)*180/PI
- Find the resulting X force by F * cos(angle)
- Find the resulting Y force by F * sin(angle)
- Use these to assign the Force vector and apply it to the object
In general I think this okay but I feel like I am missing something as right now the forces are still a bit sporadic. I think I am making the assumption that the signs of the force (- or +) will be handled by the Trig functions above but I have a feeling that is not the case. From my logs sometimes the angle is -167 and I'm wondering if that shouldn't just be based on a 360 degree system instead? I'm assuming if that's the case then I have to do some logic to assign the correct - or + signs to the forces so it moves in a direction away from the explosion point. Can anyone point me in the right direction? I am a developer so this could be completely off :)