Fast moving object passing through other objects

爱⌒轻易说出口 提交于 2019-12-11 04:33:58

问题


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


回答1:


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.




回答2:


If you were doing something like:

transform.velocity.x += speed * Time.deltaTime;

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.



来源:https://stackoverflow.com/questions/5788261/fast-moving-object-passing-through-other-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!