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 Vanguard3000 · Dec 15, 2015 at 02:49 AM · cameraraycastcollision detectiontransform.positiondistance

Jarring "snap" on 2d Camera raycast collider

Hi, all.

I'm making an oldschool 3rd person racing game, with a camera mounted behind the player. The player is confined by walls on either side of the track, and if you get to close to said walls, the camera will clip out of the track.

My solution is to have the camera normally always be at a "camera mount" GameObject attached to the player. However, the mount raycasts out in either direction to detect the track walls. If it detects either wall, it will "push" the camera away by making its distance 10m from the wall.

So, basically, if the mount's raycast detects a wall, the math ought to be:

 _playerCamera.transform.position = _mount.transform.position - transform.right * (10 - Vector3.Distance(hit.point, transform.position));

in other words, if the player is 6m from a wall: Camera Position = mount position + (10m - 6m) = mount position + 4m therefore, the camera should be offset by 4m.

However, I find there is a distracting "snap" effect when the mount detects a wall and begins of setting the camera, though I feel like if the math is sound, the transition between the "normal" state of the camera being at the mount's position and the "wall-detected" state of ofsetting the camera from the mount should be undetectable.

I also notice that when the player moves closer to the wall after the mount has detected a wall, the camera does not remain a uniform distance from the wall, which again, it should do if the math works.

Anyway, I feel like the solution is a fairly simple one, but it's eluding me at the moment. Thanks in advance for any help you folks can provide.

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

0 Replies

· Add your reply
  • Sort: 

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

RTS camera help 1 Answer

Ray Cast not working for camera. 1 Answer

Place and size a cube at farplane of camera 1 Answer

How to use both NGUI widgets and unity UI 0 Answers

Distortion of mountains 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