Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 lepickle · Sep 11, 2014 at 05:11 PM · backgroundtopdownscrollingparallax

How to create an infinite scrolling background in top down multi-directional shooters.

I am creating an Asteroids-esque game. I'd like to create an infinitely scrolling background for top down shooters. I've tried other several scripts but it wasn't helping me.

Other videos only provides tutorials for one direction background parallax scrolling.

I was thinking if there are some sample scripts I could base my code on.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by akruckus · Sep 11, 2014 at 09:18 PM

What if you were to just create a one direction scrolling background but rotate the background object based on the direction and speed of the player? You'd have to toy around a bit because you wouldn't want any stars/planets on screen to rotate with the player object.

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 lepickle · Sep 12, 2014 at 07:02 AM 0
Share

Indeed, I've tried using some methods such as duplicating the image all over the infinite plane, but I think that's gonna be an issue in performance.

avatar image
0

Answer by Malfegor · Sep 12, 2014 at 07:48 AM

You could try make the Parallax scroll in 2 dimensions. Try the following (note: untested!)

 public static class Global : MonoBehaviour
     {
         public static Vector2 WorldMove = Vector2.zero;
     }
 

This is a class, which has to be in the scene you want to scroll. Now for the player:

 public float MoveSpeed = 5F;   
     
      public class PlayerController : MonoBehaviour
         {
             void Update()
             {
                 Global.WorldMove = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * MoveSpeed;
             }
         }

This is (obviously) the player controller script. Assign this script to a player.

Now for the 'Layers' (parallax)

 public class Layer : MonoBehaviour
 {
     private Vector2 MaxDistance;
     private Vector2 StartPosition;
 
 void Start()
     {
         transform.position = Vector3.zero;
 
         StartPosition = (Vector2)transform.position;
 
         MaxDistance = Vector2.zero;
 
         for(int i = 0; i < transform.childCount; ++i)
         {
             MaxDistance += new Vector2(transform.GetChild(i).renderer.bounds.size.x, transform.GetChild(i).renderer.bounds.size.y);
         }
 
         MaxDistance = MaxDistance / 2;
     }
 
         public void Update()
         {
             transform.Translate(Global.WorldMove * Time.deltaTime);
 
             if(transform.position.y <= -MaxDistance.y || transform.position.y >= MaxDistance.y || transform.position.x <= -MaxDistance.x || transform.position.x >= MaxDistance.x)
         {
             transform.position = StartPosition;
         }
         }
 }

The Update function might not work as properly as it should, so say so if it doesn't! Now, plant this 'Layer' class on an empty GameObject and put 4 sprites/planes for your floor in. Position them so that they make one big square. Now it should work, but as stated earlier: Untested! Hope it helps (even if only a tad).

Comment
Add comment · Show 2 · 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 Malfegor · Sep 12, 2014 at 07:54 AM 0
Share

Your ground has to be tile-able!

avatar image lepickle · Sep 13, 2014 at 04:39 AM 0
Share

Thank you, I shall try this out first.

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

25 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

Related Questions

2D Parallax Background 4 Answers

Moving Background with translated images 1 Answer

Making a point and click background. 0 Answers

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

Problem with changing the direction of an Infinite scrolling background. 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