Key code:
1Boxshape.material =NewP2. Material ();2Platformshape.material =NewP2. Material ();3 4 varMaterial =NewP2. Contactmaterial (boxshape.material, platformshape.material, {5Surfacevelocity:-50,6restitution:0.5,7friction:0.3,8Stiffness:1e79 });TenWorld.addcontactmaterial (material);
This component is needed for a common bounce effect. The effect of this code is that the block is free falling to the bezel, has a slight rebound effect, and has a right speed. According to the results of my experiment, whether it is Boxshape or Platformshape as Bodya, when Surfacevelocity is less than 0 o'clock, the block moves to the right, greater than 0 o'clock, naturally to the left. Restitution is the Bounce Force property, the default value is 1. Friction is the frictional force, the default value is 0.3. Stiffness is a stiffness attribute with a default value of 1e7. This contactmaterial class, there are other properties, but did not try out the effect, did not write to the example, is: Relaxation,relaxation of the resulting contactequation that Contactmaterial Generate
Frictionstiffness,stiffness of the resulting frictionequation that this contactmaterial generate
Frictionrelaxation,relaxation of the resulting frictionequation that this contactmaterial generate
Contactskinsize,offset to is set on contactequations. A positive value would make the bodies penetrate to all other. Can is useful in scenes where contacts need to is more persistent, for example when stacking. Aka "cure for Nervous Contacts". Really do not know how to translate, just paste it up as a memo. Practice Source Address: https://gist.github.com/yxzblue/3a66babfb93b889f0833#file-contactmaterial-html p2.js v0.6.0 package, Link: http ://pan.baidu.com/s/1mgsw7xa Password: Bj85p2.js's github address: https://github.com/schteppe/p2.js
P2. JS Touch Material (contactmaterial) memo