Skip to content

Commit e361cdf

Browse files
committed
adding friction coefficient
1 parent 687bc58 commit e361cdf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

examples/03-cloth.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
// simulation
3535
var sim = new VerletJS(width, height, canvas);
36+
sim.friction = 1;
3637
sim.highlightColor = "#fff";
3738

3839
// entities

js/verlet-js/verlet.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ var VerletJS = function(width, height, canvas) {
8282

8383
// simulation params
8484
this.gravity = new Vec2(0,0.2);
85-
this.friction = 0.8;
85+
this.friction = 0.99;
86+
this.groundFriction = 0.8;
8687

8788
// holds composite entities
8889
this.composites = [];
@@ -111,14 +112,14 @@ VerletJS.prototype.frame = function(step) {
111112
var particles = this.composites[c].particles;
112113

113114
// calculate velocity
114-
var velocity = particles[i].pos.sub(particles[i].lastPos);
115+
var velocity = particles[i].pos.sub(particles[i].lastPos).scale(this.friction);
115116

116117
// ground friction
117118
if (particles[i].pos.y >= this.height-1 && velocity.length2() > 0.000001) {
118119
var m = velocity.length();
119120
velocity.x /= m;
120121
velocity.y /= m;
121-
velocity.mutableScale(m*this.friction);
122+
velocity.mutableScale(m*this.groundFriction);
122123
}
123124

124125
// save last good state

0 commit comments

Comments
 (0)