Box2d Loop Shape,确定平滑着陆
我正在编写一个游戏,其中一个圆形落在由数百个顶点组成的 b2LoopShape 上。
我试图通过使用接触侦听器来确定我的着陆是否平滑(沿着边缘着陆或垂直于边缘着陆),但无法正确执行。
有什么想法吗?
I'm writing a game where a circle shape lands on a b2LoopShape consisting of a few hundred vertices.
I'm trying to determine whether my landing is smooth or not (landing along the edge or perpendicular to the edge) by using a contact listener but can't get it right.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
环形由多个边缘段组成。您需要遍历所有边缘段并找到每条边缘上距离圆中心最近的点。所有这些中最接近的点应该是实际用于碰撞的点。如果它位于其所属边缘段的“尖端”之一,则该圆撞击边缘的末端。如果它位于边缘中间的某个地方,它就会顺利着陆。
我可能会误解你所说的“平滑”的意思,但无论如何,如果你执行上述操作,你将获得实际被击中的边缘的两个端点,以及圆的行进方向,因此你可以使用这些来顺利与否自己决定。
A loop shaped is made up of multiple edge segments. You will need to loop over all the edge segments and find the closest point on each edge to your circle's center. The closest of all these should be the point actually used for the collision. If it is at one of the 'tips' of the edge segment it belongs to, the circle hit the end of the edge. If it is somewhere along the middle of the edge, it landed smoothly.
I may be misunderstanding what you mean by 'smoothly', but in any case if you do the above you will have the two endpoints of the edge that was actually hit, and the direction of travel of the circle, so you can use these to decide for yourself whether it's smooth or not.