Reputation: 6624
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
Upvotes: 1
Views: 5401
Reputation: 21522
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.
Upvotes: 1
Reputation: 2618
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.
Upvotes: 1