corona物理引擎中物体有粘性的解决办法
From:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/
Objects are sticking to walls
Another challenge people are running into is that sometimes, slow-moving objects stick to walls or other objects that they should be bouncing off of. While it’s impossible to tell you exactly how to fix your problem in particular, here are some things you can look into:
Try adjusting the friction and bounce properties of your physics bodies. Since friction affects how “sticky” a surface is, and bounce affects how “bouncy” an object is, you might try playing with the bounce property of the moving object, and the friction property of the static object to see if that helps solve your problem.
Mentioned as a proposed solution to the previous problem, the physics.setVelocityIterations() and physics.setPositionIterations() functions might also help prevent objects from “sticking” to others unintentionally.
Finally, as a last resort, if tweaking properties and changing global physics settings doesn’t work for you, you could always add a collision listener to one of the objects, and apply a small amount of force (in the opposite direction of travel, to simulate a bounce) whenever a collision occurs. Of course, this is a workaround, so we highly recommend tweaking properties and settings first.
Don’t be reluctant to experiment!
Of course, the above was only a small handful of the most common issues people are having when it comes to getting things to behave how they want, but there are more. The best thing you could do to overcome these challenges is to strive to get a deeper understanding of how Box2D physics in Corona works.
To gain this understanding, I recommend opening one of the “Physics” sample code projects, such as Bullet, and play around with physics.setScale() to see how it affects the simulation. Additionally, play with the objects’ density, bounce, and other properties/functions (such as friction and physics.setVelocityIterations()) to get an even better understanding of how the various properties can affect your physical game world.
对象粘在墙上
同时,困扰人们的一个问题是,移动慢的物体本应弹回的,但是它们去粘在墙上或其他的物体上。虽然还不可能确切地告诉你如何解决你的问题,但这里有几件事你可以看看:
1.试着调整它的摩擦力和弹力。由于摩擦力影响粘性的表面,弹力影响对象的弹力,你可以试着调整移动对象的弹力和静止对象的摩擦力,这可能解决你的问题。
2.之前提到的解决办法,physics.setVelocityIterations() 和physics.setPositionIterations() 函数可能会阻止不经意的粘性。
3.如果调整属性和全局的物理设置对你没有效果,还有一个最后的方法,你可以给每一个对象添加一个碰撞监听,并在碰撞时加上一个小的力(在相反的方向模拟一个弹力)。当然,这只是一个变通方案,我们还是强力推荐你首先调整属性和配置。
当然,以上只是遇到这类事情时少数人最常见的问题,但是有更多的。最好你能努力对Box2D在Corona是如何工作的有一个深入的理解。
为了获得理解,我提醒你打开一个例子学习一下,比如子弹,通过改变physics.setScale()来看它影响了什么。此外,改变密度,弹力,和其他属性、方法(比如摩擦力和physics.setVelocityIterations())来更好地理解这些属性如何在你的物理环境中起作用。
-------------------------------------------------------------------------------
http://developer.anscamobile.com/forum/2011/02/11/sticky-walls#comment-51781
Make sure your physics body's shape definition is no more than 8 points and is in a clockwise pattern. If not you will get sticky objects --Ansca Stafff
确认具有物理属性的对象定义没有超过8点(是对于线来说吗?)并且是顺时针方向的。如果没有这么做 ,对象将由粘性。
-------------------------------------------------------------------------------
参考资料:
new API?
physics.setMKS( key, value) physics.getMKS( key )
The argument 'key' can be:
"velocityThreshold" (corresponds to b2_velocityThreshold)
"timeToSleep" (corresponds to b2_timeToSleep)
"linearSleepTolerance" (corresponds to b2_linearSleepTolerance)
"angularSleepTolerance" (corresponds to b2_angularSleepTolerance)
These will be available in build 700 (or after, if 700 fails to post)
http://developer.anscamobile.com/forum/2010/11/10/expose-box2d-velocitythreshold-parameter-help-sticking-objects
-------------------------------------------------------------------------------
http://developer.anscamobile.com/forum/2010/11/10/expose-box2d-velocitythreshold-parameter-help-sticking-objects#comment-51776
http://www.ludicroussoftware.com/blog/2011/09/01/corona-physics-forced-bouncing/