博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
corona物理引擎中物体有粘性的解决办法
阅读量:5174 次
发布时间:2019-06-13

本文共 3651 字,大约阅读时间需要 12 分钟。

From:

-------------------------------------------------------------------------------

-------------------------------------------------------------------------------

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())来更好地理解这些属性如何在你的物理环境中起作用。

-------------------------------------------------------------------------------

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)

-------------------------------------------------------------------------------

转载于:https://www.cnblogs.com/superchao8/archive/2011/12/21/2296132.html

你可能感兴趣的文章
优化深度神经网络(二)优化算法 SGD Momentum RMSprop Adam
查看>>
2016腾讯全球合作伙伴大会马化腾《给合作伙伴的一封信》
查看>>
Effective JavaScript Item 38 调用父类的构造函数在子类的构造函数
查看>>
Android 开发新方向 Android Wear ——概述
查看>>
固定浮窗的实现代码【转载】
查看>>
C#Windows的HelloWorld
查看>>
Xcode清除缓存、清理多余证书
查看>>
weblogic 优化设置 http://wenku.baidu.com/view/c42e7a5bbe23482fb4da4cf2.html
查看>>
.net 获取 虚拟目录名字
查看>>
BZOJ 入门OJ 2006: [Noip模拟题]七天使的通讯
查看>>
linux下使用g++编译cpp工程
查看>>
JAVA详细运行过程及与平台无关性
查看>>
jsonp跨域总结
查看>>
c#设计模式之观察者模式(Observer Pattern)
查看>>
数论——质数筛法
查看>>
创建sum求多元素的和
查看>>
onchange 、oninput 区别&remove、empty
查看>>
UILabel的常见用法
查看>>
用户线程和内核线程的区别
查看>>
Java异常超详细总结
查看>>