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 ch1mera · Feb 10, 2012 at 12:36 AM · cameraraycastterrain

Raycasting on camera corners

So, I'm trying to tackle an issue where the edge of the terrain can be seen when zoomed out to a certain point. Instead of hard-capping the range of the camera, its been suggested that I use raycasting to determine whether the void is being seen by the camera, and move the camera forward accordingly.

My question is, is there anyway to send out 4 rays from the corners of the camera instead of the center? If not, is there a work around for this issue that anyone can recommend? I've been trying to read up on raycasting, but I honestly can't seem to get a grasp on how to properly utilize it.

Thanks,

Comment
Add comment · Show 1
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 ch1mera · Feb 10, 2012 at 09:01 PM 0
Share

Thanks for the replies, definitely set me on the right path.

3 Replies

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

Answer by Berenger · Feb 10, 2012 at 12:46 AM

You can send rays from the corner, like that :

 Ray topLeft = Camera.main.ScreenPointToRay(new Vector3(0, 0, 0));
 Ray topRight = Camera.main.ScreenPointToRay(new Vector3(Screen.width, 0, 0));
 Ray botRight = Camera.main.ScreenPointToRay(new Vector3(Screen.width, Screen.height, 0));
 Ray botLeft = Camera.main.ScreenPointToRay(new Vector3(0, Screen.height, 0));

or

 Ray topLeft = Camera.main.ViewportPointToRay (new Vector3(0, 0, 0));
 Ray topRight = Camera.main.ViewportPointToRay (new Vector3(1, 0, 0));
 Ray botRight = Camera.main.ViewportPointToRay (new Vector3(1, 1, 0));
 Ray botLeft = Camera.main.ViewportPointToRay (new Vector3(0, 1, 0));
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 samiwood96 · Jul 09, 2021 at 05:42 PM 0
Share

Thanks this definitely helped me. Not sure but seems like at least for the top answer the names might be mixed up? Copy paste from the docs "Screenspace is defined in pixels. The bottom-left of the screen is (0,0); the right-top is (pixelWidth -1,pixelHeight -1)."

avatar image
0

Answer by MD_Reptile · Feb 10, 2012 at 01:27 AM

If you follow the tutorials on 3dbuzz they go into handling this issue with camera control, and the way the do it is to draw 4 rays FROM the camera, to the player, with a "lookAtTarget" so that if those rays get blocked, it draws the camera further in to the player, until the ray is not hit. Might want to check it out:

http://www.3dbuzz.com/vbforum/sv_showvideo.php?v=4915

Also they go into making it impossible to enter the wall partially, where you get your player up against a wall, and the like FOV allows you to see into the blank world behind it...It can stop that too, really cool tutorials there!

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 Owen-Reynolds · Feb 10, 2012 at 04:17 AM

If you don't even think about how to code it, but just try to draw pictures of where the camera should be as you move/turn near the edge, it gets pretty ugly. If you're running towards the edge of the map, do you suddenly get an overhead view? Running along the right edge narrows my view so I can't see left of me?

Making the terrain a little larger than you need, and raising the sides a little, looks surprisingly good. Or, plant some "tree" billboards around some edges (DnD online does this -- looks OK.) You will have to limit the camera to stay within the terrain (looking from off-terrain to where you can see the edge, that looks terrible.) But that's a simpler problem.

It's also easy to be too sensitive to something no one else would see. People know there are edges, and often expect "hi, I'm the edge of the world" signals. Take a look at professional 3D games -- lots of ways to force a bad camera view.

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

9 People are following this question.

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

Related Questions

Make the terrain ignore Raycast if in between Camera and Player? 1 Answer

orbiting mouse controlled camera goes thru terrain 3 Answers

RTS camera help 1 Answer

How to get Camera Collision Detection on Terrain 1 Answer

Inserting UnityScript Raycasting code into C# script ? 3 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