Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by brad2233 · Oct 05, 2021 at 09:27 AM · cameradetectioncamera-lookfov

How can I stop the Camera from detecting things behind walls.

I am working on a game and one of the mechanics is a security camera. I want it to work so that if you get seen by the camera when the timer goes off, you're out; however, as of now with my current code, even if you hide behind a wall, if you are still technically in the camera's FOV, you get "detected" and you lose the game. I want to know how I can get the same effect I have now, but without the camera being able to detect things. The only solution I can think of at the moment would be creating triggers in the areas that the camera technically couldn't see you and have the camera ignore the player if the player is in them, but that would require a total redesign of the 5 maps I already have completed. Any suggestions? P.S. I know the code is probably EXTREMELY unoptimized

The current code for the detection script is below:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;

public class checkForPlayer : MonoBehaviour {

 public GameObject player;
 public GameObject loseScreen;
 public GameObject skillCheck;
 public AudioSource timerWarning;
 public Text hideWarning;
 public Transform target;
 Camera cam;
 public GameObject shoppingList;
 public GameObject civillian;

 public float timeRemaining;
 public static bool ifLost;
 public Rigidbody playerBody;

 void Start()
 {
     cam = GetComponent<Camera>();
     ifLost = false;
 }

 void Update()
 {

     if (timeRemaining > 0)
     {
         timeRemaining -= Time.deltaTime;
     } else
     {
         CheckForPlayer();
         hideWarning.text = "";
         timeRemaining = 15;
     }

     if (timeRemaining < 5 && timeRemaining > 4.9)
     {
         if (!ifLost)
         {
             hideWarning.text = "HIDE";
             if (!timerWarning.isPlaying)
             {
                 timerWarning.Play();
             }
         }
         
     }
 }

 public void CheckForPlayer()
 {
     Vector3 viewPos = cam.WorldToViewportPoint(target.position);
     if (viewPos.z > 0 && viewPos.x > 0 && viewPos.x < 1 && viewPos.y > 0 && viewPos.y < 1)
     {
         player.GetComponent<Rigidbody>().velocity = (transform.forward * 0);
         loseScreen.SetActive(true);
         player.GetComponent<cartController>().enabled = false;
         hideWarning.text = "";
         skillCheck.SetActive(false);
         ifLost = true;
         shoppingList.SetActive(false);
         civillian.GetComponent<Animator>().enabled = false;
         civillian.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationZ;
     }
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

240 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

360 FOV camera. 1 Answer

How to transform camera view as a different shape? 1 Answer

Make Camera follow rotation of 2 Players 1 Answer

CineMachine Camera Movement is inverse 1 Answer

Way to rotate Camera with standart Vectors(forward,right, up) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges