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 Bebops · Sep 21, 2016 at 06:57 PM · c#camerasmoothdampsmoothfollow

SmoothFollow to play catchup to player position

Hey guys im curretly working on a 3rd person game and I am using the Unity script "SmoothFollow" as a base for the game Camera.

I would like the camera to play catchup to the players position. For example: the player would move in a direction, then the camera would slowly move to the players new position.

I have tried to implement this behavior into the script many times using but to no success. I understand lerping, damping, etc.. but have no idea how to actually implement them correctly into this already existing script provided by Unity:

 var wantedRotationAngle = 45;                                           
 var wantedHeight = target.position.y + height;
 var currentRotationAngle = 5f;
 var currentHeight = transform.position.y;
 
 currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, rotationDamping *Time.deltaTime);
 
 currentHeight = Mathf.Lerp(currentHeight, wantedHeight,heightDamping * Time.deltaTime);
 
 var currentRotation = Quaternion.Euler(0,currentRotationAngle, 0);
 
  transform.position = target.position;
 transform.position -= currentRotation * Vector3.forward * distance;
 
 transform.position = new   Vector3(transform.position.x,currentHeight,  transform.position.z);
 
 transform.LookAt(target);    

If anyone has any insight on how I may acheive this, it would be greatly appreciated.

EDIT: I understand that I could use a gameobject that lags behind the player and instead use that as the camera target. It would acheive the desired effect but it isnt really a soloution that I could learn somthing from.

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 Bebops · Sep 23, 2016 at 11:39 AM

Managed to work out a solution to my question, I will post it just in case anyone in the future has the same problem as I did.

 Vector3 wantedPosition;
 
 wantedPosition = new Vector3(target.position.x, currentHeight, target.position.z);
 
 wantedPosition -= currentRotation * Vector3.forward * distance;
 
 transform.position = Vector3.Lerp(new Vector3(transform.position.x, currentHeight,  transform.position.z), wantedPosition, distanceDamping * Time.deltaTime);
 
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

why target switching of smooth camera not very smooth ? 0 Answers

Changing Targets - Smooth Damping X and Z on SmoothFollowCamera 0 Answers

Multiple Cars not working 1 Answer

Smooth Follow Camera that Keeps Up 0 Answers

Smooth Camera follow script is causing framerate drops when moving 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