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
0
Question by Instability · Aug 09, 2012 at 12:55 PM · camera2dplatformersmooth followside scroller

Improve smooth 2d side scroller camera to look more fluent

Hi,

I am using a very simple linear interp camera with the key lines being

     Vector3 newPos = target.position + new Vector3(0, relativeHeigth, -zDistance);
     transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * dampSpeed);

(this is from the camera script of the marble game in 5 Unity game examples: C#). This works beatifully for a slow paced game, but in my case velocities are a bit higher (often rigidbody.velocity.magnitude reaches 20 under normal scalings) and when the game is fast my marble doesn't look sharp but its edges seem to be unsteady. If I change the script to a primitive

 this.transform.position = new Vector3(target.transform.position.x, this.transform.position.y, this.transform.position.z);

then the edges look much sharper (but obviously the smooth following of the camera is gone).

Any ideas how in the smooth script the unsteadiness of the edges can be approached?

Best, Instability

Comment
Add comment · Show 5
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 Jeffom · Aug 09, 2012 at 02:03 PM 0
Share

Have you tried tilting the step for the lerp? like im guessing the dampspeed is a const from the examples, you should try to calculate a step that is relative to the object you're following.

avatar image Seth-Bergman · Aug 09, 2012 at 02:19 PM 0
Share

if your camera is perspective, you might try switching to orthographic..

avatar image Instability · Aug 09, 2012 at 04:15 PM 0
Share

Sorry I don't get your comment, can you expand it? What do you mean by step? Time.deltaTime * dampSpeed? By tilting the step, do you mean adjusting dampSpeed? I tried this but the effect at large velocities doesn't go away, even at very high dampSpeed.

avatar image Bunny83 · Aug 09, 2012 at 04:18 PM 0
Share

@Instability: You even named his post a comment, why do you answer with an answer to your question? Answers should answer the question. Q&A, you know?

I've converted you answer into a comment.

avatar image Instability · Aug 09, 2012 at 04:22 PM 0
Share

First post on unityAnswers! Thx bunny (this should be a comment).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jeffmoretti · Jun 01, 2016 at 04:24 PM

I had a similar problem with scrolling 'smoothness' myself. My code that I had written was as follows (make sure to read the note below after the code):

 public GameObject player;

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {

     Vector3 offset = transform.position - player.transform.position;

     bool changeInX = false;
     bool changeInY = false;

     Vector3 newCameraPosition = transform.position;

     if (offset.x > 3)
     {
         changeInX = true;
         newCameraPosition.x = (player.transform.position.x + offset.x) - (offset.x - 3);
     }
     else if (offset.x < -3)
     {
         changeInX = true;
         newCameraPosition.x = (player.transform.position.x + offset.x) - (offset.x + 3);
     }

     if (offset.y > 2)
     {
         changeInY = true;
         newCameraPosition.y = (player.transform.position.y + offset.y) - (offset.y - 2);
     }
     else if (offset.y < -2)
     {
         changeInY = true;
         newCameraPosition.y = (player.transform.position.y + offset.y) - (offset.y + 2);
     }

     if (!changeInX)
     {
         newCameraPosition.x = transform.position.x;
     }

     if (!changeInY)
     {
         newCameraPosition.y = transform.position.y;
     }

     transform.position = newCameraPosition;

 }

The thing that I did which fixed it to smooth scrolling was to change the void Update() function to a void LateUpdate() function. Once I did that, the scrolling was much more smooth! Hope this helps :)

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

11 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

Related Questions

Free Look Camera Pivot 1 Answer

Lock main camera on x-axis 2 Answers

How to get GUI text to appear on screen in 2d? 1 Answer

2d camera movement 1 Answer

Restricting camera to within areas. 2D Adventure Platformer 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