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
1
Question by Unamine · Feb 23, 2011 at 12:31 PM · camerafollowsmooth

Problems with the script Smooth Follow

Well I added the script Smooth Follow, my camera to follow my character, because the problem is that there are some movements that I do with my character, the camera passes through leaving the ground to see what is inside. I would like to fix it so that when she turned the camera crash into the ground without the cross and did not cease to focus on character

Thx 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

1 Reply

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

Answer by Statement · Feb 23, 2011 at 12:36 PM

One trivial addition to this could be to raycast to the next camera position. If the raycast hit anything, limit the movement to the hit position, and perhaps subtract some length yet to avoid the camera being "exactly on" the ground.

I don't have unity installed at the moment so I can't verify this code would work but basically you'd have two points. One represents the current location and the other represents the next location (that the camera wants to go to);

Vector3 prevPos; // Assume containing interesting data. Vector3 nextPos; // Assume containing interesting data. Vector3 deltaPos = nextPos - prevPos;

Vector3 direction = deltaPos.normalized; float length = deltaPos.magnitude;

RaycastHit hit; if (Physics.Raycast(prevPos, direction, out hit, length)) { nextPos = prevPos + direction * hit.distance; // Or just use nextPos = hit.point.. }

// Use nextPos that should now "clamp" to the terrain. // You probably want to subtract (direction * someAmount), // to avoid the camera being placed exactly on the terrain. // Make use of layermasks if you need to fine adjust collision rules.

Comment
Add comment · Show 3 · 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 Joshua · Feb 23, 2011 at 12:41 PM 0
Share

I have also been struggling with this. If you could give a small example as to how you would implement this (not asking you to write it all out course, just giving me an idea of how I would write that). I'd of course be for ever thankful. :-)

avatar image Statement · Feb 24, 2011 at 02:44 AM 0
Share

Added some code that could illustrate this.

avatar image Unamine · Feb 24, 2011 at 10:58 AM 0
Share

Thanks, I'll try your example

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

No one has followed this question yet.

Related Questions

Camera follow smoothness problem 1 Answer

Smooth Follow Problem 1 Answer

Why does the camera smoothly follow in one direction but not the other? 0 Answers

Need help/advice with 2D Camera follow script. 1 Answer

Smooth Follow Rotation 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