@@ -21,7 +21,7 @@ const config = {
21
21
debug : {
22
22
showBody : true ,
23
23
showStaticBody : true
24
- }
24
+ } ,
25
25
}
26
26
} ,
27
27
scene : {
@@ -160,6 +160,16 @@ function wrap(p) {
160
160
}
161
161
}
162
162
163
+ function clampVelocity ( p , maxSpeed )
164
+ {
165
+ let v = p . body . velocity ;
166
+ let speed = Math . sqrt ( v . x * v . x + v . y * v . y ) ;
167
+ if ( speed > maxSpeed ) {
168
+ p . setVelocity ( v . x * maxSpeed / speed , v . y * maxSpeed / speed ) ;
169
+ }
170
+
171
+ }
172
+
163
173
function update ( ) {
164
174
const self = this ;
165
175
const players = self . players ;
@@ -170,10 +180,11 @@ function update() {
170
180
let torque = 5.0 ;
171
181
if ( input . left ) {
172
182
//playerPhysics.setAngularVelocity(-0.3/4);
173
- playerPhysics . body . torque = - torque ;
174
- } else if ( input . right ) {
183
+ playerPhysics . body . torque += - torque ;
184
+ }
185
+ if ( input . right ) {
175
186
//playerPhysics.setAngularVelocity(0.3/4);
176
- playerPhysics . body . torque = torque ;
187
+ playerPhysics . body . torque + = torque ;
177
188
178
189
} else {
179
190
//playerPhysics.setAngularVelocity(0);
@@ -188,7 +199,8 @@ function update() {
188
199
//player.setAcceleration(0);
189
200
}
190
201
191
- wrap ( playerPhysics ) ;
202
+ wrap ( playerPhysics ) ; // enable wrap plugin didn't work for me
203
+ clampVelocity ( playerPhysics , 10 ) ;
192
204
193
205
players [ player . playerId ] . x = playerPhysics . x ;
194
206
players [ player . playerId ] . y = playerPhysics . y ;
@@ -221,7 +233,7 @@ function addPlayer(self, playerInfo) {
221
233
222
234
// player.setDrag(100);
223
235
// player.setAngularDrag(100);
224
- // player.setMaxVelocity(200);
236
+ //player.setMaxVelocity(200);
225
237
226
238
console . log ( 'Player collision filter' , player . body . collisionFilter , 'star collision' , self . star . body . collisionFilter , 'options' , options ) ;
227
239
0 commit comments