Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by budwiser · Oct 21, 2012 at 01:37 AM · hidinggame-object

How to make an object to be only partially seeable by another object?

I was wondering about how to find out if an object is able to see another object.

Well, I found this How can I check the line of sight to see if the player is visible to the enemy? and it works well.

But how should I implement something like partial obstacles on the way?

For example if I want to make a bush which makes it 10% harder to detect someone from behind it. And maybe with binoculars the detection handicap could be reduced to 5%.

What is the correct way to achieve this?

Comment
Add comment · Show 2
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
avatar image Muuskii · Oct 21, 2012 at 03:09 AM 0
Share

Do you want to put Random number generation in your game? Some people may find RNG annoying as it makes your game unpredictable.

avatar image budwiser · Oct 21, 2012 at 05:29 PM 0
Share

Well, is there a better way to do what I described?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Muuskii · Oct 21, 2012 at 06:04 PM

Looking at the code you listed, I'm thinking it might be a good idea to use Physics.RaycastAll since you can receive ALL of the hits along your raycast (Note that order is not guaranteed.)

This means that your ray can go through bushes and glass. Here's some untested code to describe what I'm thinking:

         RaycastHit[] hits;
         float gaurdAwareness = 1.0f;   //This is a scalar to multiply with normal awareness
         hits = Physics.RaycastAll(transform.position, transform.forward, 100.0F);
         int i = 0;
         while (i < hits.Length) {
             RaycastHit hit = hits[i];
             Obstacle obstcl = hit.transform.GetComponent<Obstacle>();
             if(obstcl ) {
                 gaurdAwareness -= obstcl.blockingPower; //how much the bush "blocks sight"
             }
             i++;
         }

Basically, you get the "blocking power" of each obstacle between the "guard" and the "sneaker" to get the guard awareness which is then multiplied by the general awareness which is based upon distance, "sneaker" stance, and guard alertness level. You can also throw light levels and some scalar based on how long the guard has been "looking at the sneaker" in there.

If after all of these computations; the guards general awareness of the sneaker is higher than some threshold value, the "sneaker" is revealed. Otherwise, it remains hidden.

Comment
Add comment · Share
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
avatar image
0

Answer by tavoevoe · Oct 21, 2012 at 05:42 PM

This is a kind of open ended question, so I've got a kind of open ended response.

Instead of using physics.raycast, use physics.raycastall.

It will return a list of everything along a line, but not in order. So, once you get a list of everything in the line, you'll have to do some tests.

1) make sure the target is somewhere along the line.

2) Measure the distance to the target and store that.

3) Check every other object returned's distance. If its less than the player distance, your ray hit it.

4) For each object you hit, check its type. If its a bush, add 5%, if its a wall, add 10%, etc.

Comment
Add comment · Share
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

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

11 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

Related Questions

Moving an object back and forth with mouse click 0 Answers

Player hiding and detecting 0 Answers

highlight item in game 1 Answer

Hiding and showing multiple objects 1 Answer

How to check if a point is seeable by a camera 5 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