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 /
avatar image
0
Question by DevLuke · Dec 28, 2015 at 01:49 PM · c#optimizationprocedural meshface

How Would I Find Out if a Player can See a Certain Face of a Mesh?

Hey people! I'm making a game that is somewhat like a voxel game, except that the blocks are not on a 3D grid. They can be anywhere in the y axis. Now, if I want to optimize this game, how would I go about checking to see if a face of a block is visible to the player? Is the best way to just look through the list of 50-100 blocks to find one that would hide the face? Also, I cannot use raycasts because more than one object might make a face covered.

Thanks!

Comment
Add comment · Show 7
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 callen · Dec 28, 2015 at 02:47 PM 0
Share

I don't see why you still couldn't use raycasts? It will hit any object that may be blocking, assu$$anonymous$$g the physics layers are set up correctly. I'm also curious what you are trying to optimize for.

To answer in $$anonymous$$ath terms though, you could use a dot product of the player's Forward vector and the vector corresponding to the face's normal. Or it seems like Vector3.Angle would do something similar.

avatar image Fattie · Dec 28, 2015 at 03:28 PM 0
Share

simply use a raycast, as you guessed. that's perfectly correct and an everyday thing to do. (as callen has already said, it's no problem (why would it be?) that more than one item might be in the way.)

avatar image DevLuke Fattie · Dec 28, 2015 at 05:08 PM 0
Share

The reason I didn't want to use raycasts was because multiple blocks together might block a face ins$$anonymous$$d of just one big one. Could raycasts still do this somehow?

avatar image Fattie DevLuke · Dec 29, 2015 at 12:23 AM 0
Share

yes no problem at all.

avatar image callen · Dec 28, 2015 at 07:32 PM 0
Share

I don't think I understand the problem you're having... If you need to find all of the objects covering your target, you could do multiple raycasts (say, aimed at each vertex of the face in question). But from my reading of your question, you don't need that do you?

So I guess I'm confused as to whether you want to know just the Boolean of "can the player see this face?" or the more involved case of "which object (or set of objects) stand between my player and this face?"

For either case, I think raycasts are still the way to go. But as I said, I'm curious what optimization this will give you, and if it couldn't be done another way.

avatar image DevLuke callen · Dec 28, 2015 at 08:36 PM 0
Share

Sorry I can't explain this well. I'll try explaining my situation using a picture:

 __     __
 | |   | |
 | |   |_|
 |_|   |_|

$$anonymous$$y problem is that I want to hide any faces that are not necessary to render, but there is no grid on the y axis in the game. Each "block" could be a completely different height, and multiple blocks could cover the face of a taller block, as I hopefully showed in the picture. In that case, the tall block's covered face does not need to be rendered.

Again, I don't know how I can explain this situation in a few words because the whole game is quite a complex concept.

EDIT: $$anonymous$$y picture did not turn out the best, but hopefully you can still understand what I'm saying.

avatar image Fattie DevLuke · Dec 29, 2015 at 12:24 AM 0
Share

There is absolutely no problem. JUST RAYCAST

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by callen · Dec 29, 2015 at 03:36 PM

If I'm reading the correctly, the only reason for this problem is to determine whether or not to render a face?

Do you realize that the engine can do this for you? I highly suspect that Unity's implementation of Occlusion Culling will outperform yours, (hit the link for set up details), especially because there is likely some overhead with enabling/disabling renderers manually, which the engine can internally optimize out.

You may be trying something more complex which you did not describe, but it looks like you're trying to do Occlusion Culling, so use Unity's implementation for maximum performance.

Comment
Add comment · Show 1 · 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 Fattie · Dec 29, 2015 at 03:43 PM 0
Share

Callen has absolutely hit the nail on the head.

It's quite common on this site that folks ask questions, and the answer is actually "oh that is totally done for you, it's the whole point of a game engine!"

For example quite often you get people asking "I'd like to simulate what happens when two blocks hit each other -- and one bounces the other along!" Of course that is the whole entire raison d'etre of a game engine.

Exactly as Callen says, DevLuke, I think it's the case you're just mistaken DevLuke and thankfully, any ordinary rendering engine completely does this for you.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

So what's Mesh.UploadMeshData do exactly? 3 Answers

Is it possible to calculate batch count of each material ? 0 Answers

C# basic perfomance question 2 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