How to make a wall that disappears like Layers of fear ?
Hello, I would like to know how to make a trigger system that activates when the player looks at another place and then makes a wall disappear behind him. Thank you! Thank you!
Like at 00:31. https://www.youtube.com/watch?v=LLH_aKd09YE
Answer by Vega4Life · Jul 22, 2019 at 06:31 PM
For the example in the youtube video, you need 3 prefabs that are almost identical. A prefab wall, a prefab wall with a door, a prefab wall with a door that is bricked up. This makes them easily replaced/swapped out for other walls.
When the user goes into the room, there is a trigger. When the user exits the trigger (onTriggerExit), and is inside the room, then the wall can be swapped for the prefab of the door that is bricked up. Honestly, this is probably the most work, as you need to make sure they are indeed in the room - you don't want to change prefabs if a user walks into the trigger but walks out the way they came (because that is still a trigger exit). So, you would need to check the room with (maybe) a raycast to the floor - and check the floor space.
The second wall change happens when new wall that was just swapped (door bricked up) comes in LOS to the user. There are a lot of examples out there for that - which is basically checking to see if the user is looking at a specific point. If the new wall is in LOS, the back wall is swapped for a new prefab of a wall with a door.
public class LookAt : MonoBehaviour
{
[SerializeField] GameObject target;
[SerializeField] float lookDelta = 0.8f; // 1.0f is directly looking at gameObject
// Update is called once per frame
void Update()
{
Vector3 direction = (target.transform.position - transform.position).normalized;
float dotProduct = Vector3.Dot(direction, transform.forward);
if (dotProduct >= lookDelta)
{
// Change wall
}
}
}
Example above is using a dot product to determine if an object is looking at another. A product of 1 is looking directly at it, -1 is looking completely away.
So how do you know if the player is looking at a specific point in the room? Thank you for your answer
Your answer
![](https://koobas.hobune.stream/wayback/20220612205317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to turn off isTrigger when on Entering and turn on isTrigger on Exiting. 1 Answer
Trigger finds objects without being activated 0 Answers
Trying to get bool statement to work in OnTriggerStay2D 1 Answer
Moving triggers possible? 0 Answers
How to detect the vertices of water4 using a trigger? 0 Answers