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 AyJ_ · Mar 21, 2017 at 01:40 AM · unity 52dmovementvelocitymoving

2D endless scrolling game - Which method is best for moving objects without lags?

Simply put, I am developing endless 2D game, where you can move character forward or backward using accelerometer.

There are lots of objects and I don't know which method is the best for moving these objects and not decrease performance of this game.

Method 1: I only use movement on X axis using accelerometer on my main character (or Player) where is attached Main Camera. It means that only main character is moving on X axis and other game objects are staying on their X positions. I used this method first, but then I realized that if anybody got really far in this game, there would be a problem with values on X axis, because this number could be higher than maximum value of float number. Yes, I know that it is highly improbable, but it might happen.

Method 2: I don't use movement on X axis via accelerometer on my main character, but use this value as inverse in RigidBody2D.velocity of all other objects. It means that X position of my main character would always be 0 and if I use accelerometer for moving main character forward (right direction) then I use this value as inverse on X axis of all other game objects.

So which method is the best for moving objects in 2D endless game? If you have any other which is better, I will be very thankful for it.

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

Answer by Ran-Quan · Mar 21, 2017 at 06:09 AM

Moving a single character is cheaper and more scalable. You can move the main character first, then when it go beyond a certain distance, just shift everything left so that the x coordinate of the character resets to zero.

Note that a properly implemented pooling system is also very important for an endless scrolling game.

Comment
Add comment · Show 3 · 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 AyJ_ · Mar 21, 2017 at 09:56 AM 0
Share

Thank you for your answer. Yes, I am using pooling system, anyway what do you mean by properly implemented? I am using it like this: if I know that I will need e.g. about 3 enemies, then I create 3 enemies on the start of the game and then just disable them when they go out of screen (beyond $$anonymous$$IN X of the screen) and re-enable and re-position them on the start of screen if I need them again. Is it ok?

avatar image Ran-Quan AyJ_ · Mar 21, 2017 at 10:19 PM 0
Share

Yes, for basic scenarios that will do it. $$anonymous$$ore complicate games may involve some sort of resource management such as releasing assetbundles or monitoring total memory usage.

avatar image AyJ_ Ran-Quan · Mar 22, 2017 at 11:29 AM 0
Share

Ok, thanks.

avatar image
0

Answer by tanoshimi · Mar 21, 2017 at 06:59 AM

You acknowledge yourself that the likelihood of anyone getting far enough for floating-point precision to cause an issue is highly improbable. As a generally accepted guide (and assuming you're using 1 Unity unit = 1 metre scale), if you want millimetre-precision, you should keep coordinates under 10,000. If you're happy with centimetre-precision (in worldspace), you can go to 100,000. Is your character really likely to run more than 100km?

Use Occam's razer - when given two choices, take the simplest (Method 1: move the player), and only worry about float precision if it becomes an issue.

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 AyJ_ · Mar 21, 2017 at 09:57 AM 0
Share

Thank you for your answer.

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

How to prevent jitter with movement over curved slopes 0 Answers

How to measure Speed? 2 Answers

How do I get my character to keep his left and right momentum in the air while also disabling movement controls until grounded? 0 Answers

Weird Rigidbody2D.velocity.x problem, float out of control 0 Answers

2D Directional top down movement,Topdown 2d Directional Movement 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