- Home /
How to do a raycast to make my player unable to move through certain objects?
Im making a 2D top-down game where the player walks around and in different ways interacts with the environment (like the first Zelda games). All graphics are displayed on planes, however I have given them box colliders to make sure they collide with each other, which they also do.
What I want is to make the player unable to move through objects with a certain tag. And since I dont want any physics in the game, I dont want to use the Rigidbody physics.
Any ideas? I've heard that raycasting might do the trick, but im not very familiar with it.
Hmmm... you say the game uses no physics, but are using Box colliders to keep them apart, which is physics.
Answer by AlucardJay · Dec 27, 2012 at 12:42 PM
although this is meant for physics, there is no reason you couldn't use the same technique :
http://wiki.unity3d.com/index.php?title=DontGoThroughThings
http://answers.unity3d.com/questions/365477/passing-objects.html
Useful tutorial : http://www.unity3dstudent.com/2010/08/intermediate-i01-raycasting/
more from Unity3Dstudent (start at the bottom of the page, then work up) : http://www.unity3dstudent.com/category/modules/
The Unity Scripting Reference : http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html