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 POLYGAMe · Aug 17, 2011 at 11:54 AM · 2dbackgroundscrollingtiling

Scrolling background help - seams appearing...

Hi there,

I have the following code that I am using for a background that I want to scroll left and right, repeating. Unfortunately, I am getting a gap between the objects... sometimes it overlaps, other times there is the gap... is there any more precise way to scroll two objects as one?

 private var fLeftPosition = -21.07282;
 private var fRightPosition = 21.07282;
 
 
 function Update () 
 {
 
     transform.localPosition.z = 5.785643; // Locks the Z position
     
     // When reaches left limit, reset position
     if (transform.localPosition.x < (fLeftPosition * 2))
     {
         transform.localPosition.x = (fRightPosition * 2);
     }
     // When reaches right limit, reset position
     else if (transform.localPosition.x > (fRightPosition * 2))
     {
         transform.localPosition.x = (fLeftPosition * 2);
     }
     
     // Move background when turning left and right
     if (PlayerControl.g_bPlayerOneIsTurningLeft == true)
     {
         transform.Translate((-PlayerControl.g_fRotationSpeed / 5) * Time.deltaTime, 0, 0);
     }    
     else if (PlayerControl.g_bPlayerOneIsTurningRight == true)
     {
         transform.Translate((PlayerControl.g_fRotationSpeed / 5) * Time.deltaTime, 0, 0);
     }
     else
     {
         transform.Translate(0, 0, 0);    
     }
 }
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 POLYGAMe · Aug 17, 2011 at 08:29 PM 0
Share

Bump - anyone? Really stuck here...

avatar image POLYGAMe · Aug 17, 2011 at 09:51 PM 0
Share

Hmmm... maybe I wasn't clear enough... I'm trying to scroll the background, so I have two planes. When one plane hits the far left position, it jumps back to its original position. The same happens when it scrolls the other way, but reversed. The problem I'm getting is that there seems to be a gap opening up between the two planes, even though speed is exactly the same. This process works on my 2D shooter, but in this more complicated game I'm having issues...

1 Reply

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

Answer by Joshua · Aug 17, 2011 at 09:50 PM

Instead of, when the object get's too far left/right directly setting the position back to the other far right/left position add the length difference to them.

What you're doing now is saying if you're too far left, meaning it's position is minLeft + a bit, go to far right. But the position of the second on is then offset by that 'a bit'.

So replace

 transform.localPosition.x = (fRightPosition * 2);

with

 transform.localPosition.x += (fRightPosition * 2)-(fLeftPosition * 2);
Comment
Add comment · Show 5 · 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 POLYGAMe · Aug 17, 2011 at 09:55 PM 0
Share

Thanks Joshua! I shall incorporate the code right away! Love this site ;-)

avatar image POLYGAMe · Aug 17, 2011 at 09:57 PM 0
Share

Woohoo, works perfectly! Thanks again!!!

avatar image Joshua · Aug 17, 2011 at 09:59 PM 1
Share

Haha glad it helped! Just fyi, if you're happy with an answer don't just accept it but also upvote it. It doesn't really matter for me, because I already have a high enough karma, but you might make others happy with it in the future ;)

avatar image POLYGAMe · Aug 17, 2011 at 10:04 PM 0
Share

Okay, cool :)

avatar image POLYGAMe · Feb 21, 2012 at 10:22 AM 0
Share

I have found that animating the UVs works even better :)

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

parallax scrolling background 2 Answers

Large finite background for vertical scroller - best approach? 1 Answer

How to follow a game object by camera but with a slower speed? 2 Answers

2D Infinite Vertical Background scrolling 0 Answers

Scrolling and Looping 2D Background Image 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