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 /
  • Help Room /
avatar image
0
Question by ading25 · Aug 29, 2016 at 10:36 PM · unity 2dscrollingparallax

Jittery background when implementing parallax effect

I'm trying to create a 2D sidescroller that implements a parallax effect for the background (there is also a ground which does not use the effect). The camera follows the player, and the player controls a unit that can move left and right. In other words, there is no set speed for the ground to move at so I can't just have the background scroll at a fraction of the speed as the ground.

My current solution is to move the background a fraction of the player's x velocity. I add this in the update function of the backgrounds script:

 transform.position = transform.position + Vector3.right * playerRb.velocity.x * Time.deltaTime * 0.9f;

Here, i'm trying to make the background scroll at 90% of the player's speed. This actually seems to work, except for the fact that it is extremely jittery when I test it in Unity (I left out infinite scrolling for now).

https://sendvid.com/akhkgv8y

Does anyone know why this may happen? Is there something wrong with the way that I position the background images?

Comment
Add comment · Show 2
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 mj321 · Aug 30, 2016 at 05:26 AM 0
Share

That looks like it's jumping backwards sometimes. Check if playerRb.velocity.x becomes negative at any time.

avatar image ading25 mj321 · Aug 30, 2016 at 08:49 AM 0
Share

I think you might be right, except ins$$anonymous$$d of negative velocities, I may have had a negative acceleration. I think the velocity wasn't strictly increasing like I expected to, it jumped backwards sometimes, which may have caused the jittering effect. Thanks!

1 Reply

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

Answer by CapitalLlama · Aug 30, 2016 at 07:23 AM

You should be able to do something simple like this (assuming you only want the background moving on the X-axis

 Vector2 _x= new Vector2 (player.transform.position.x, 0);
         transform.position = _x * 0.9f;

player is the gameObject of the player

I tried this myself and it didn't have any stuttering. Let me know how it works out for you!

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 ading25 · Aug 30, 2016 at 08:50 AM 0
Share

This worked great for me! I'm not sure why I was using velocity ins$$anonymous$$d of position. Thanks!

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

67 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

Related Questions

2D Parallax with zoom 0 Answers

Inverted parallax 0 Answers

Parallax Scrolling Performance Issue - Gets Laggy after a bit 0 Answers

Is it possible to use gyroscope to produce a parallax tilt effect in Unity 2D? 0 Answers

Moving a parallax background automatically without moving the camera 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