Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Rangr · Nov 18, 2015 at 06:40 AM · c#pointsstealthcover

Finding Boundaries of a Cover Object

I am working on a stealth game. The cover objects are giving me issues though. I am using lots of empty GameObjects for detecting the cover object and defining their bounds. This should be a simple issue that could be resolved during level creation but in the future I'd like to incorporate a way for players to make levels as well, so GameObjects labeled with a tag "Cover" are simply attached to prefabs that I'm using to create the levels.

alt text

Given this picture, where the blue is the player, the red are cover points, and the black is wall, I need a way to constrict the player to the boundaries of the wall using the cover points. I am completely at a loss though. I will say that I had originally used colliders on the walls but it was slow and didn't work with the level creation system.

My first thought was to check the rotation of the closest cover point, then find the closest two points that are facing the same direction that are at the end of an object. Two problems arose with that idea: I don't know how to find the end points, and there are times when the closest end points would be the wrong end points (as in the example below).

alt text

My most recent thought is to check the rotation of the prefab, then check for objects with tag "Cover", then take objects on that list that have the same rotation and either x or z position (depending on rotation) as the prefab. From there I'd find the farthest to the left and right of the point and save that. Then I could just use those saved coordinates any time that point is used for cover. This idea seems to have potential but I don't know how I'd stop at the end of the wall rather than just going to the farthest possible point.

If anyone has any ideas on how I can accomplish this, I would very much appreciate it, because I've been stuck on this problem for over a week and have no ideas on how to fix it.

Thanks!

sample-2.png (38.4 kB)
sample-1.png (35.9 kB)
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

1 Reply

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

Answer by Rangr · Nov 27, 2015 at 07:31 AM

If anyone cares to know, I figured it out. Here is the code I used:

 List<GameObject> lefts = new List<GameObject>();
         List<GameObject> rights = new List<GameObject>();
         GameObject[] obj = GameObject.FindGameObjectsWithTag("Cover");
         foreach(GameObject go in obj){
             if(go.transform.position != transform.position && (Mathf.Round(go.transform.eulerAngles.y) == Mathf.Round(transform.eulerAngles.y) && Mathf.Round(transform.eulerAngles.y) == 0f))
             {
                 if(go.transform.position.x == transform.position.x)
                 {
                     if(go.transform.position.z < transform.position.z)
                     {
                         if(FindClosest().transform.position != transform.position)
                         {
                             lefts.Add(go);
                         }
                         //at the end, find the closest from the list of ends, that is coverpoints 1, and second closest which is leftJumpPoint
                     }
                     else if(go.transform.position.z > transform.position.z)
                     {
                         if(FindClosest().transform.position != transform.position)
                         {
                             rights.Add(go);
                         }
                     }
                 }
             }
             else if(go.transform != transform && (Mathf.Round(go.transform.eulerAngles.y) == Mathf.Round(transform.eulerAngles.y) && Mathf.Round(transform.eulerAngles.y) == 180f))
             {
                 if(go.transform.position.x == transform.position.x)
                 {
                     if(go.transform.position.z > transform.position.z)
                     {
                         if(FindClosest().transform.position != transform.position)
                         {
                             lefts.Add(go);
                         }
                         //at the end, find the closest from the list of ends, that is coverpoints 1, and second closest which is leftJumpPoint
                     }
                     else if(go.transform.position.z < transform.position.z)
                     {
                         if(FindClosest().transform.position != transform.position)
                         {
                             rights.Add(go);
                         }
                     }
                 }
             }
         }

plus an if for 90 degrees and 270 degrees.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Game Object Positioning 1 Answer

How do i Instantiate sub-Points with in Multiple Points?? 0 Answers

Vectors side determing by a line. Please help me out !!!! 0 Answers

Adding points from another script 1 Answer

Order points from array based on 8-connectivity (Moore neighborhood) 1 Answer


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