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 aorata · Jul 31, 2012 at 04:32 PM · backgroundscrollingparallax

Moving Background with translated images

Hello, I have been having some trouble making a moving background that consists of images that represent waves.

What I want to do is have 2 images: Wave1 and Wave2.

I want to move them from right to left continously, by moving them and changing their position once they get off camera.

So it looks like Wave1 Wave2 (changeWave1 position) Wave1 Wave2 Wave1 Wave2 Wave1

I hope that is clear.

Anyway, All I do is move them with Lerp, and check their position relative to the Camera, if they get out of view, I change their positions from the left of the camera to the right of the camera, so they appear again on the right side of the camera. (exit on left, change position, appear on right).

That works well, the problem is when I move the camera (it follows a player), the script constantly checks if the wave is off camera, and moves it on camera again (relative to the cameras position of course), and SOME TIMES the position is not set right, and a little space appears between the wave images...

I need to fix this, is there a simpler way of doing what I'm doing? is that little white space due to the time it takes my computer to run the code?

Please help, I hope I made myself clear enough, as english is not my native language.

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 Loius · Jul 31, 2012 at 07:48 PM

Say your wave object is SIZE units in size.

 if ( wave.transform.position.x < minimumX ) {
   wave.transform.position.x += SIZE;
 }

This will force your object to "align with itself"; if it has a repeating image it should line up properly. This is because you're setting it relative to itself so you know it will match its own graphics.

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 Loius · Jul 31, 2012 at 08:00 PM 0
Share

Oh, haha, I actually just built this for my own project. This one does some parallax. $$anonymous$$y objects are twenty units square, and each 'layer' is a gameobject containing a 3x3 grid of nine of those objects (as children).

 #pragma strict
 
 var layers : Transform[];
 private var multipliers : float[];
 
 function Start () {
  multipliers = new float[ layers.length ];
  multipliers[0] = 1;
  for ( var ix : int = 1; ix < layers.length; ix++ ) {
  multipliers[ix] = multipliers[ix-1] * 0.9;
  }
  StartCoroutine($$anonymous$$ove());
 }
 
 function $$anonymous$$ove() {
  var ix : int;
  while ( true ) {
  for ( ix = 0; ix < layers.length; ix++ ) {
  layers[ix].position += Game.backgroundSpeed * multipliers[ix] * Time.deltaTime;
  if ( layers[ix].position.x < -10 ) layers[ix].position.x += 20;
  if ( layers[ix].position.z < -10 ) layers[ix].position.z += 20;
  if ( layers[ix].position.x >  10 ) layers[ix].position.x -= 20;
  if ( layers[ix].position.z >  10 ) layers[ix].position.z -= 20;
  }
  yield;
  }
 }

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

parallax scrolling background 2 Answers

Parallax scrolling background performance problem 4 Answers

trouble with getting the background to show past the midground in 2d parallax backgrounds 0 Answers

2D Parallax Background 4 Answers

How to create an infinite scrolling background in top down multi-directional shooters. 2 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