码迷,mamicode.com
首页 > Web开发 > 详细

P2.JS之触碰材质(ContactMaterial)备忘

时间:2015-02-13 00:16:04      阅读:1253      评论:0      收藏:0      [点我收藏+]

标签:

关键代码:
 1 boxShape.material = new p2.Material();
 2 platformShape.material = new p2.Material();
 3 
 4 var material = new p2.ContactMaterial(boxShape.material, platformShape.material, {
 5     surfaceVelocity: -50,
 6     restitution: 0.5,
 7     friction: 0.3,
 8     stiffness: 1e7
 9 });
10 world.addContactMaterial(material);
 
像很普遍的弹跳效果就需要用到这个组件了。
 
技术分享
 
这段代码的效果其实就是方块自由落体到挡板上,有轻微反弹效果,并且有向右的速度。
 
根据我试验的结果,不管是boxShape还是platformShape作为bodyA,当surfaceVelocity小于0时,方块向右移动,大于0时,自然向左。
 
restitution为反弹力属性,默认值1。friction是摩擦力,默认值0.3。stiffness是刚度属性,默认值1e7。
 
这个ContactMaterial类,还有其它的属性,不过没试出效果来,就没写到例子上去了,分别是:
 
relaxation,Relaxation of the resulting ContactEquation that this 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 be set on ContactEquations. A positive value will make the bodies penetrate more into each other. Can be useful in scenes where contacts need to be more persistent, for example when stacking. Aka "cure for nervous contacts".
 
实在也不知道怎么翻译,就直接贴上来当作备忘吧。
 
 
p2.js v0.6.0 的压缩包,链接:http://pan.baidu.com/s/1mgsW7xA 密码:bj85
p2.js 的Github地址:https://github.com/schteppe/p2.js

P2.JS之触碰材质(ContactMaterial)备忘

标签:

原文地址:http://www.cnblogs.com/yxzblue/p/4289350.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!