- Home /
Don't want game object seen when it goes past a wall
Hi, so I'm making a game with this robot who has this "scanner." The scanner is just a gameobject which acts as a visible indicator of where the robot can see. However, if the robot gets close to a wall, the scanner will go through that wall and be seen on the other side. I don't want to robot to stop before the scanner hits the wall, but instead I want to make the part of the scanner on the other side of the wall invisible. I would also be okay with any other way to make the object be seen on one side of the wall, while hiding the part on the wrong side of the wall! Any help is very appreciated!
Answer by djenningsais · Apr 01, 2021 at 06:38 PM
Greetings!!
I am thinking if you added a collider to the wall you could then collect the point of collision and adjust your scanner length.
Hope this helps!!
@djenningsais Thanks so much for the response! I was thinking about that, however I'm quite new to Unity, and C# in general, and sadly don't know exactly how to do that! You don't have to write out the code for me, but if you could point me to a video or document that explains the basics of how to do that it would be amazing!
I would start by setting up your box colliders (assu$$anonymous$$g 3D):
https://docs.unity3d.com/Manual/class-BoxCollider.html
Then look into collision:
https://docs.unity3d.com/ScriptReference/Collision.html
You would probably want to see if collision.getContact would work for you.
https://docs.unity3d.com/ScriptReference/Collision.GetContact.html
If the sensor is a "laser" it may be beneficial to look into RayCasting:
https://docs.unity3d.com/ScriptReference/Collider.Raycast.html
Hope this helps!!
Your answer
Follow this Question
Related Questions
Creating ship energy shields effect 2 Answers
spawning on collision 1 Answer
Is it possible to setup plane collision for shuriken at runtime? 0 Answers