- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题
If the bullet reaches its destination the body is shaking, back and fort from destination to previous position then back again to destination and so on.. and so fort... Strange behavior
示例代码
Vector2 targetPosition =
// Copied target position and subtracted by bullet position
Vector2 targetDirection = targetPosition.cpy().sub(bulletPosition);
float distance = bulletPosition.dst(targetPosition);
float speed = 16;
Vector2 velocity = targetDirection
.cpy() // Copied target direction
.nor() // normalize to avoid getting the direction as speed
.scl(speed); // scaled by speed
// the distance is not accurate, so we get the time step as defined precision
float DEFINED_PRECISION = Constants.TIME_STEP;
// check if the bullet is near or maybe match the touch point
if(distance >= DEFINED_PRECISION) {
// move the bullet
body.setLinearVelocity(velocity);
} else {
// stop the bullet
body.setLinearVelocity(0,0);
}
最佳答案
可能是你的 DEFINED_PRECISION
太低了 - 你应该在每一步中注销 body 的
位置(甚至通过添加类似 System.out.println(body. getPosition());
在你的循环中)并检查它是否更大。
当时的情况是
距离
大于DEFINED_PRECISION
所以它正在向前移动距离
大于DEFINED_PRECISION
,所以它正在向后距离
大于DEFINED_PRECISION
...这就是它颤抖的原因:)
首先,您应该更改您的DEFINED_PRECISION
- 检查一帧中移动了多少 body ,这个值除以2
应该是 DEFINED_PRECISION
(因为两帧之间的 body 和目标之间存在最大距离)。另外我猜想将目标的位置直接设置为 body 比将 velocity
设置为 (0,0)
更好
else {
body.setTransform(target.getPosition().x, target.getPosition().y, body.getAngle());
}
当然,如果你的步幅不是很大——那么变化将是不可见的,最终位置将恰好是目标的位置
关于java - libgdx box2d body - 为什么 body 在到达接触点位置后摇晃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38239532/
我想让我的 UICollectionViewCell 在长时间按下 (UILongPressGestureRecognizer) 后摇晃以便删除一个项目。 我读过这个post和另一个 one . 我按
我有两个 SkSpriteNode,分别是 left-ball 和 right-ball。它们从屏幕的两侧流出。 我为这两个球实现了碰撞检测。但是我注意到,在我添加碰撞检测之前,球在没有任何晃动效果的
我在使用Github的 Action 时遇到了一个奇怪的问题。我有一个Gradle任务,可以将发行说明打印到文件中(在本地工作得很好)。但是使用GitHub操作似乎无法将–pretty=format:
我将 Cannon.js 与 Three.js 结合使用。我设置了一个场景,其中有 5 列,每列 4 个 block 相互堆叠。 我希望它们能够与我计划添加到场景中的其他对象进行交互。然而,列中的 b
我在 tableview 上使用了自动布局,但在 HeightforRowAtIndexPath 中计算了图像框架、标题和副标题以及高度。 & 滚动 tableview 抖动 最佳答案 在 viewD
我是一名优秀的程序员,十分优秀!