快速移动的物体穿过其他物体 [英] Fast moving object passing through other objects

查看:101
本文介绍了快速移动的物体穿过其他物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Unity还是很陌生,并且正在举一个小例子.实际上,我有一个可以随箭头键移动的立方体.现在我在路上有墙,我希望我的物体撞到墙,但它穿过墙.

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

推荐答案

总体思路是跟踪对象的最后一个位置,然后在它们移动时将射线从当前位置投射到最后一个位置.检查射线是否有碰撞,如果有碰撞,您已经通过了一个物体.

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.

这篇关于快速移动的物体穿过其他物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆