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 sotha_sil · Jan 18, 2015 at 11:11 PM · cameracollisionthird-personclipping

Preventing camera clipping

Hello, I wondering if anyone found a good way to prevent camera from going through walls in tight areas? I went through tens of tutorials and threads but the most common method seems to be casting ray to see if camera is obstructed by something, the problem with this is every tree or small object that will obstruct the camera makes it jump to the player.

I recorded this video https://www.youtube.com/watch?v=5E2DTWJYERU From this asset demo https://www.assetstore.unity3d.com/en/#!/content/11716 Which is basically Buzz3d 3rd person tutorial

anyway you can see how camera jumps every time tree gets in the way. Now one thing I could do is introduce layers for raycast to ignore the trees etc, but that is kind of a pain in the long term for environment artists.

One other method I found was from this tutorial series https://www.youtube.com/watch?v=b0PvJ4AWvWQ&list=PLKFvhfT4QOqlEReJ2lSZJk_APVq5sxZ-x where he kind of checks vector intersection point between camera and player and move camera on X and Z to that vector. But he still have collision issues in the corners.

I stumbled upon Unreal Engine tutorials and they had this spring physics system, where camera had collision and was spring attached to player and if camera collided with something spring would contract. Would this work for unity? Have any of you guys tried this?

Or if you have any solutions that works well work 3rd person camera that would be awesome!

Thanks in advance

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MadMenyo · Jan 19, 2015 at 01:39 AM

You could add tags to everything that should jump the camera, or perhaps if easier add tags to the things that should not jump the camera.

Another thing is to just keep the camera really close when in tight space. If you are bothered with the visibility of your player you can try lowering the opacity on the materials of the meshes between the camera and the player.

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
1

Answer by AgapitoTori · Mar 27, 2016 at 08:13 PM

@sotha_sil A way to avoid the jumping is to make the camera move slowly only on the way out. This means that when the raycast hits an obstacle the camera moves immediately forward (when it collides with the tree), but when the raycast stops detecting an obstacle, instead of instantly returning to the max distance the camera is set to, you slowly interpolate it, this kinds of smoothes the camera movements, especially in enclosed spaces.

Also, in order to avoid wall clipping when the character is too close to walls consider using spherecast instead of raycast, a spherecast with a big enough radius will make it impossible for the nearClipPlane of the camera to "half traverse" a wall.

Finally I would strongly recommend to thourougly check the protectFromWallClipping script that comes with the standard assets (or just use it), I haven't found any camera tutorials better than this about the subject (for my coding level at least).

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

27 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

Related Questions

MouseOrbitImproved camera distance seemingly inverted 1 Answer

Camera looking through objects when touching 1 Answer

Camera Question 0 Answers

Stop Dashing through walls 1 Answer

3rd Person Cam Collides when it shouldn't 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