• 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
Question by Neumo · Jun 11, 2015 at 10:12 PM · unity 2dplayer movementbackground

Unity2D Parallax Scrolling approach concern

I've read plenty of answers as to how to approach a moving background when making a 2D game using Unity. My question though, is more targeted to the following type of game. Currently, I want to make a game where the player does move from left to right, and at the same time make the background move. So, is this still achieved with Parallax Scrolling, where I would only move the background if the player's walk animation is played? and then if the player is in the idle animation, would the background stop? Or for this situation, is it valid to create a large static image in the background, and just have a camera following the player?

I'm not interested in how to code it, I'd just like to know what approach should be considered.

Thanks,

Comment

People who like this

0 Show 0
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
Best Answer

Answer by AlwaysSunny · Jun 11, 2015 at 10:12 PM

I'm fairly confident the effect should relate to the movement of the camera, not the player. Small difference, and maybe I'm wrong, but methinks it'll look more natural if it's determined by camera motion.

Create a quad which faces the camera. It can even be a child of the camera. Stretch the quad to fill the field-of-view. Place your background material on the quad. Write a script which changes the UV offset of the material based on camera movement. The scale of this offset delta determines the intensity of the parallax effect.

If using a single texture, either allow the texture to move so little the camera never observes a seam, or use a looping texture.

If you need multiple textures, the approach becomes considerably more complicated, and will involve multiple quads and some sneaky game design trickery known as "quilting" or "treadmilling", where you physically move a group of textured quads around based on camera motion to maintain the illusion of a single seamless background; sort of like a patchwork quilt, where only the patches that can be observed exist in a given moment.

Best luck,

Comment
Neumo

People who like this

1 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 Neumo · Jun 12, 2015 at 01:24 PM 0
Share

I appreciate the answer, will have it in mind. But I'm wondering if it's acceptable for a 2D platformer, to have parallax scrolling in the background, but at the same time have the background be large and have a camera that follows the player through the entire Background. Either that, or should I make it like an infinite runner, but stop the offset of the background if the player is not pressing right/left.

Thanks again,

avatar image AlwaysSunny · Jun 12, 2015 at 11:01 PM 0
Share

I'm afraid I still do not understand the question. You'd have to show an example of the effect, or a diagram, and/or use much stronger nouns and adjectives to convey your meaning. The language in your question does not communicate anything meaningful.

Your target platform (desktop vs mobile) determines your target size for textures. For mobile, I would not recommend any textures larger than 1024, with 512 being a decent average target. On desktop, that upper limit is 4096, and the average target is more like 1024 or 2048.

Always use the smallest texture you can while maintaining the power-of-two rule and achieving the level of fidelity you want. If you want more pixel data than these rules allow for, use multiple textures.

Regarding parallax effects, all I can say is that in every example I've seen of a parallax effect, the effect is driven by the motion of the camera. It should have nothing to do with whether the player is pressing the movement keys. It should be driven by the camera's position delta.

Does this help answer your question? If not, please reconsider the language you are using to attempt to ask it. I don't know what the phrases "background large enough...camera follows the player through the entire background" or "make it like an infinite runner" mean to you.

avatar image AlwaysSunny · Jun 13, 2015 at 06:23 PM 0
Share

Ah, now I grasp what you're asking. It's always better to give more than enough information than assuming others will know how you're using a word or phrase. :)

I would not want to use the fixed-player approach. I would strongly recommend a more traditional approach. It's easier to conceptualize, program, and build for.

If your game will have dynamically generated content or you want "infinite" environments, you may face certain challenges that using the fixed-player approach would spare you, but these are challenges you'll need to get experience dealing with eventually in other genres, so you might as well face them head on. The only real benefits of the fixed-player approach are conveniences that bypass certain challenges like when and where to load / unload objects.

Hiding seams / creating a looping background texture is best accomplished in your image editing program of choice. Having multiple textures "stitched together" to form a long seamless strip will require some very careful planning and the use of the aforementioned quilting / treadmilling technique. If possible, pull elements from the background - trees, hills, mountains, into separate textures on their own quads, and animate the quads moving to simulate parallax. This is vastly superior to using a single texture or painting seamless textures for numerous reasons. These environmental "background" decorations can be spawned dynamically just like any platform objects your game will have, and can use the same system for detecting when to spawn and die.

Platforms and background decorations can die according to their distance from the player. Spawning them in an interesting way is a little more challenging, but half the fun will be coming up with a strong solution. It might be based on maintaining a certain target number of said objects, for instance, which always spawn X units away from the player, just outside the camera's field of view.

Best,

avatar image Neumo · Jun 13, 2015 at 07:10 PM 0
Share

This information does help answer my question, but partially. But to clear things up, this is what I meant.

  • By background large enough, I meant exactly what you explained about texture sizes. So let's say I'll be including in my game multiple textures of size 1024, at different z positions.

  • By camera follows the player through the entire background, I meant that instead of going the parallax scrolling route, what If I chose to actually move the player and have the camera follow it along. I've seen examples where the player is moved by changing its' Rigidbody2D, either applying forces or changing its' velocity directly, and at the same time the camera's x position changes to follow the player.

  • By Infinite runner, I meant going for the approach of applying parallax scrolling. Where instead of the player's x position being changed, the player always remains stationary at (0,0), as well as the camera is stationary, and the background moves. In this case the player would always be playing a walk/run animation.

So here is my question, if my game targets the desktop platform, is it ok that I go the route of say create three textures of sizes 1024, all positioned at different z's, but without animating the textures. Simply leave them stationary. Have the user move the player through arrow keys, and as the player moves, the camera moves. This way, the player could move left to right, up, stay still, etc.. And the left corner of the Background would be the beginning of the Level, and the right corner the Ending of the level.

So is it right if I do it this way?

I apologize if I'm not being clear, I'm new to this deal of asking a questions in forums.

Trust me I appreciate your time, and I'm trying my best to be clear on this.

avatar image Neumo · Jun 13, 2015 at 10:25 PM 0
Share

This morning I was reworking my answer, thinking that yesterday I hadn't posted while I was at work :D. But then when I posted my new answer this morning, I saw that what I had written yesterday had been posted as well haha. So I deleted the old one...anyways. If you see that another answer of mine, similar to what you just answered to is posted, ignore it.

Thanks dude, that helps me more than enough to what approach to account for.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Particle system behind tthe background 2D 4 Answers

Using rays to spider climb fluidly in 2D 0 Answers

What aspect ratio should the slider background use 0 Answers

Using a timer in conjunction with two push buttons from Arduino input 1 Answer

Unity 2D character can slightly go through wall. 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