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 omaglana · Aug 17, 2018 at 06:54 AM · 2d gamecamera-movementtransitionsnap

How to apply fast & slow camera transition.

Hello, I know there is a lerp function there that smoothens the camera but I wanted it to work the other way around. Lets say starting position of the player is at the left side of the camera/screen and when the players goes around the right edge (or as long as more than half width) screen travelled I want to camera to snap to the player but with smooth transition and this is the hard part I wanted to make the camera move fast as long as it is less than half the players distance travelled and apply a slow speed as the camera travels more than half the distance of player.

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

Answer by Ermiq · Aug 17, 2018 at 01:55 PM

EDIT: No, it's not gonna work. Just did some tests and, as I expected, the camera just stick to the player. The only way to flee away is to warp the player instantly, but it's pointless, because the camera will reach him again very fast.

EDIT AGAIN: I've changed Lerp to MoveTowards and now it seems to be working. The speed is going to be less than 0 when the camera stays too far beyond the maxDistance, so I used another if statement to get it back (closer to the player), otherwise it can't reach the player:

 float currentDistance;
 float minDistance = 1f;
 float maxDistance = 10f;
 float speed;
 
 currentDistance = Vector3.Distance (camera.position, player.position);
 speed = (maxDistance - currentDistance) / maxDistance;
 
 if (currentDistance > minDistance) // to keep the camera in distance from the player
 {
     // multiplier '1.5f' should be less then the player's speed,
     // otherwise he could never run away from the camera when it reach him
     camera.position = Vector3.MoveTowards (camera.position, 
         player.position, speed * 1.5f * Time.deltaTime);
  }
  if (currentDistance >= maxDistance) // to make camera chase the player if he'd ran too far
  {
      camera.position += (player.position - 
          camera.position) * 1f * Time.deltaTime;
      // or maybe it's better to use 'Lerp' here to get smooth movements
      camera.position = Vector3.Lerp (camera.position, player.position, 0.1f);
  }



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 omaglana · Aug 19, 2018 at 01:52 PM 0
Share

Sorry I forgot to mention that the functionality should be called, not at the update method. I will try to implement this and see.

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

94 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 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 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 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

Cinemachine camera shake on button press 0 Answers

Camera animation issue 0 Answers

How can I get my camera to only follow my player down along the Y axis? 2 Answers

Smooth transition of position between animations 0 Answers

How to create a cinemachine custom camera offset in the aiming direction 0 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