Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are trying to emulate friction, the easiest way, is to <strong>know the velocity</strong> and use a mathematical model, or <em>differential equation</em> to approximate it.</p> <pre><code> dx -c * -- dt </code></pre> <p>basically, the force of friction is proportional to the velocity and in opposite direction. Thus, you can calculate the force of friction (or drag) simply as follows:</p> <pre><code>objects[i]-&gt;force = -drag_coefficient * objects[i]-&gt;velocity </code></pre> <p>If you do not know the velocity, it gets difficult to get good results, as you may have a force pushing right, while the object is moving left (therefore you would apply drag to the wrong direction).</p> <h3>Edit:</h3> <p>Actually, not all kinds of friction depend on the <em>magnitude (speed) of the velocity</em>, <strong>dry friction</strong> is often referred as just taking the <em>direction of the velocity</em> into account:</p> <pre><code>force = -drag_coefficient * sign(velocity) </code></pre> <p>However computationally this becomes unstable as velocity reaches 0, overshoots it and oscillates back and forth.</p> <p>Another model is the one for <strong>wet friction</strong>, that is the one I used in the first example:</p> <pre><code>force = -drag_coefficient * velocity </code></pre> <p>This means that as your object is running faster, it will be slowed down more by friction. Think for example of the force of air, as you are running, the faster you are running, the more the air is trying to slow you down.</p> <p>Neither of the models above is 100% accurate, but for a game they should be more than enough</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload