7
\$\begingroup\$

I am making a game in Unity. I have an object e.g. cube. I want to release air from it like fan so that when other cubes come closer, it throws them away. What velocity,force etc I will need to do that?

\$\endgroup\$
1

2 Answers 2

11
\$\begingroup\$

While the aerodynamic effects caused by a fan can be quite complex to model accurately, it is sufficient for most cases to model the force it applies after the Inverse-Square Law.

It means that the force it applies to another object is divided by the distance multiplied with itself.

Another factor you could or could not model depending on how physically correct you want to be is the wind drag of the objects which are pushed by the fan. Wind drag means that objects with a large surface exposed to the wind direction receive more force from the wind than those with a smaller surface (again, overly simplified. The aerodynamics are a lot more complex in reality). When you want to model this, you also need to multiply the force with the surface area of the object which is pushed.

The complete formula would then be:

appliedForce = fanForce / (distance * distance) * surfaceArea

There is, however, a pitfall in this formula: it has a singularity when the distance is 0. When the distance is below 1, the force will be more than the intended maximum. When the distance gets very small, the force can become extremely strong. This could lead to quite glitchy behavior. To fix this issue, add 1 to your distance calculation, or cap the distance at 1:

appliedForce = fanForce / (1.0 + distance * distance) * surfaceArea

or

if (distance < 1.0) distance = 1.0;
appliedForce = fanForce / (1 + distance * distance) * surfaceArea;    

More accurate results could be reached by an actual physical simulation of aerodynamics, but this is a highly complex field, both in regards to development time and computational resources. Unless physically accurate aerodynamics are a core gameplay-element of your game, it is unlikely to be worth the hassle.

\$\endgroup\$
2
  • \$\begingroup\$ I don't understand why you would divide by the surface area, shouldn't you be multiplying by it? \$\endgroup\$
    – Joren
    May 21, 2013 at 15:31
  • \$\begingroup\$ @Joren I am multiplying by the surface area. In most programming languages there is no operator precedence between division and multiplication, so they are executed in the order they are written in. \$\endgroup\$
    – Philipp
    May 21, 2013 at 19:33
1
\$\begingroup\$

You could simply calculate the distance ( you can use any mesh for collision clipping to represent the "air flow" limits), the closer it gets the higher the force you apply to it in that direction. Of course this isn't as accurate, but you could add noise to the direction of the velocity.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .