- Home /
Going through wall
I need help in building a script for my game, I want to allow the character to be able to pass through a wall by targeting a wall using raycasting as the starting point, from that starting point make a ray or something that targets the area after the wall. Then the player walks toward the starting point and then the player gets teleported across, and able to access to and fro.
But how do I code the part where I create 2 points by targetting a wall, one on the side where the player is facing and the other side of the wall where the player is supposed to teleport across?
Here is an example of what I mean if you don't fully understand what I am trying to do.
1| wall | 2
So when I aim at the wall and it creates the start point at 1, I want to script 2 to appear at the other side of the wall.
Answer by sneftel · Jul 11, 2011 at 03:24 PM
Once you use Physics.Raycast
to identify the entry point, you can use the Collider.Raycast
function (not the Physics.Raycast
function) on the wall with a second ray going in the other direction. The origin point should be far enough along the original ray that it won't be inside the wall, and the direction is negated.
I don't quite understand how Collider.Raycast works even after reading unity references, would you $$anonymous$$d explaining?
Assu$$anonymous$$g I use Fire1 to send a ray towards the wall, how am I supposed to script Collider.Raycast to project a ray through the wall to the other side? As in the direction and also the distance?
You call Collider.Raycast on a collider, and you pass it a ray, and it tells you where the ray hits the collider.
I'm not sure how to explain further... the second ray is on the same line as the first, but pointing in the other direction. One ray starts on the left side of the wall and points towards the wall; the other starts on the right side of the wall and also points towards the wall.
Is it possible that I use Collider.Raycast to start from the point where I hit the wall using Physics.Raycast and then cast a ray through the wall and then returns me another hit value that records the position on the other side of the wall?
So when I use Physics.Raycast towards the wall on the left side, how do I call Collider.Raycast on the right side?
Answer by manlymen361 · Nov 20, 2011 at 10:12 AM
create a camera and make a new layer called gun then put that camera u just created to the layer gun and put ur weapons to the layer gun and make sure that camera is on depth only and change the depth to 1 and there u go