快速移动的物体穿过其他物体
我对 Unity 还很陌生,正在做一个小例子。实际上我有一个可以用箭头键移动的立方体。现在我的路上有墙,我希望我的物体撞到墙上,但它穿过墙。
我也使用过此代码,但没有结果:
http://www.unifycommunity。 com/wiki/index.php?title=DontGoThroughThings
I am pretty new to Unity and am making a small example. Actually I have a cube which moves with my arrow keys. Now I have walls on the road, and I want my object to hit the wall but it pass through the wall.
I also have used this code, but no result:
http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
总体思路是跟踪对象的最后位置,然后当它们移动时,从当前位置向最后位置投射一条射线。检查射线是否有碰撞,如果有,则说明您穿过了一个物体。
如果您已经穿过另一个对象,请将当前对象设置为碰撞报告的位置。下一帧将触发碰撞事件。
您提供的链接实际上确实做到了这一点。
The general idea is to track the last position of your object(s), and then when they move, cast a ray from the current position to the last position. Check the ray for collisions and if there are any, you've gone though an object.
If you have gone though another object, set the you current object to the position reported by the collision. The next frame will trigger the collision events.
The link you provided does in fact do this.
如果你正在做类似的事情:
这不适用于碰撞,因为你实际上没有与任何东西碰撞,你只是每帧传送固定的量。这会让你真正传送到一个物体的内部。
If you were doing something like:
That won't work with collisions because you're not actually colliding with anything, you're just teleporting by a fixed amount each frame. This causes you to actually teleport INSIDE of an object.