# \[Physics\] Friction (ice physics)

**URL:** <https://blenderartists.org/t/physics-friction-ice-physics/561311>\
**Category:** Game Engine Support and Discussion\
**Created:** [January 3, 2013, 2:21pm UTC](https://blenderartists.org/t/physics-friction-ice-physics/561311 "2013-01-03T14:21:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucrecious](https://blenderartists.org/user_avatar/blenderartists.org/lucrecious/32/8186_2.png) [@Lucrecious](https://blenderartists.org/u/Lucrecious)\
**Post date:** [January 3, 2013, 2:21pm UTC](https://blenderartists.org/t/physics-friction-ice-physics/561311/1 "2013-01-03T14:21:46Z")

</div>

Hi there.  
I’m been trying to create some nice ice physics for the project I’m working on (yes, the one still in my signature).  
Something like this:

  
(start at 4:20)

I’ve tried a variety of things. I am aware that I can just apply force to achieve a similar effect, but I want to make a general piece of code for this that only uses linear velocity (and grabs friction from the platform properties). My most successful method was using “steps”. I split the magnitude of the velocity vector, and added it to the objects current velocity every frame (so it would start slow, and then get faster; an arithmetic sequence). However; I’m not quite sure how to limit the speed, and how to go about actually making the object stop.

Anybody have a good way of achieving this?

---

<div class="post-metadata">

**Author:** ![Mobious](https://blenderartists.org/user_avatar/blenderartists.org/mobious/32/20358_2.png) [@Mobious](https://blenderartists.org/u/Mobious)\
**Post date:** [January 3, 2013, 5:44pm UTC](https://blenderartists.org/t/physics-friction-ice-physics/561311/2 "2013-01-03T17:44:16Z")

</div>

Making sure an object doesn’t exceed some maximum speed is very simple.

```auto
vel = obj.getLinearVelocity().magnitude
speed = vel.magnitude
if speed &gt; MAX_SPEED:
    obj.setLinearVelocity(vel.normalized() * MAX_SPEED)

```

A simple and effective way for slowing down an object is just to reduce its speed by some percentage of its current velocity based on the friction of the surface its on every frame.

```auto
vel = obj.getLinearVelocity()
vel *= FRICTION# where 0 &lt;= FRICTION&lt;= 1 (0 would stop the object instantly, and 1 would be no friction)
obj.setLinearVelocity(vel)

```

---

<div class="post-metadata">

**Author:** ![SolarLune](https://blenderartists.org/user_avatar/blenderartists.org/solarlune/32/7258_2.png) [@SolarLune](https://blenderartists.org/u/SolarLune)\
**Post date:** [January 3, 2013, 6:04pm UTC](https://blenderartists.org/t/physics-friction-ice-physics/561311/3 "2013-01-03T18:04:14Z")

</div>

Mobious’ method of friction was the way I used to go, but I’ve since changed to subtracting a constant amount from the object’s velocity (as the faster you go, the longer it should take to slow down).

```auto

vel = obj.worldLinearVelocity
vel.magnitude -= obj['friction'] if vel.magnitude &gt;= obj['friction'] else vel.magnitude

```

---

<div class="post-metadata">

**Author:** ![Lucrecious](https://blenderartists.org/user_avatar/blenderartists.org/lucrecious/32/8186_2.png) [@Lucrecious](https://blenderartists.org/u/Lucrecious)\
**Post date:** [January 3, 2013, 8:31pm UTC](https://blenderartists.org/t/physics-friction-ice-physics/561311/4 "2013-01-03T20:31:17Z")

</div>

Ahh, perfect, I think it’s working. I was having a lot of trouble with stopping… Thanks SolarLune and Mobious. Just took a little bit of logic. I actually used both of those ideas at some point during my tests but for some reason never thought of putting them together.

You guys can test the file if you want. WASD to move. Friction levels can be changed on the platform itself (properties).  
[nate\_setupv01.blend](https://blenderartists.org/uploads/default/original/3X/b/d/bd0d17e385ec87c50794dc0370dce5d15299e935.blend) (482 KB)  
I like dividing the velocity instead of subtracting a constant. I may change it later if subtracting proves to be better.

Oh, and SolarLune, if you want to see your platform script in action, just change the rotation and movement on the platform properties as well.
