• 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 /
This question was closed Oct 11, 2015 at 12:56 PM by xxluky for the following reason:

Other

avatar image
0
Question by xxluky · Oct 10, 2015 at 07:20 PM · 2d-platformersmoothfollow

How to make camera follow player smoothly on X axes but not on y axis?

Hi guys,

I have a camera script that follows my player smoothly using "transform.position = Vector3.Lerp..." all the time.

Now I put in the scene cannon gun that shoots my player realy fast upwards (only on y axes) and my camera is lazy to follow the player at t$$anonymous$$s point. I have already tryed to increase follow speed or parent the camera to my player but the camera always jumps on the player - that is not what I want.

I want the camera to be parented smoothly to the moving object - to the player. Is it even possible? How should I solve t$$anonymous$$s??

Or even better - to follow my player smoothly on X axes but to be instant on Y axes with smooth aim?

Now I have t$$anonymous$$s (following on X is smooth but the camera jumps on Y axes when targets the player):

 float xPos = Mathf.Lerp(transform.position.x, player.transform.position.x, smoothSpeed * Time.deltaTime);
 transform.position = new Vector3(xPos, player.transform.position.y, -10);

Please help me...

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

  • Sort: 
avatar image
2

Answer by DiegoSLTS · Oct 10, 2015 at 09:57 PM

I'm not sure I follow you... Do you want your camera to follow the player in both axis but smooth the camera movement in the x axis only? Or do you only want to follow the player in the X axis and let the y position of the camera untouched?

If it's the first one I t$$anonymous$$nk your code should work, so I'm guessing you want to do the second t$$anonymous$$ng. In that case, why are you using the player y position when updating the camera's position? T$$anonymous$$s should follow only in the X axis:

 transform.position = new Vector3(xPos, transform.position.y, -10);
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 xxluky · Oct 11, 2015 at 08:57 AM 0
Share
avatar image xxluky · Oct 11, 2015 at 12:56 PM 0
Share
avatar image ktsakiris · Jan 20, 2018 at 09:21 PM 0
Share

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

30 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

Related Questions

I cant get wall jumping to work in my 2D platformer (C#) 1 Answer

Character Controller Falls Through Box Collider Ground 1% Of The Time! 1 Answer

2D multi touch 1 Answer

My sprite animation gets messed up after a certain event occurs! How do I fix it? 0 Answers

game stop working after game loading finish on android 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