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 TehOne · Feb 25, 2014 at 05:01 PM · 2dperformanceinfiniteside-scrolling

Should I move the character and camera or the platforms?

So, I'm a total Unity noob and pretty much a game dev noob. For my first project, I'm creating a 2D infinite runner. I may never end up releasing it, but if I do it'll be on mobile as the primary platform. As such, I've seen a lot of people saying you need to be very mindful of performance.

So, I'm just wondering, what is "better" performance wise". Moving my character and camera, or moving all of the other objects in the scene? I've see examples of it done both ways and am not sure which method I should use. In my mind, it seems like moving 2 objects (character, camera) in the scene would probably perform better than moving dozens (coins, platforms, obstacles, etc). But as I'm new to Unity and pretty much game dev in general, I wanted to see what the experts might say about it. My only concern with moving just my character and camera is "world size". Can I move my character and camera to the right forever without worrying about it? This video mentions that he has to "RepositionWorld" every once in a while to avoid floating point errors. Would anyone have any examples of a "RepositionWorld" that I can look at?

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 Regalith · Feb 25, 2014 at 05:20 PM

Hmm you say you want to make an infinite runner, so what your looking at is a procedurally generated map. That means you wont have all the platforms created before the game starts, you'll only generate the next few platforms to the right of the screen and destroy them to the left(based on the assumption you're running to the right). This keeps the number of objects in the scene down to a small number, and allows for you to not have to deal with floating point errors from running too far to the right. For further optimization, you can instead of destroying and instantiating platforms, simply reset a platform to the right side of the screen once its past the left side. (calling instantiate and destroy is far less efficient than simply creating the platforms before hand and recycling them). This I'd say would be your best bet for making this game, just remember to keep poly counts and draw calls low, and your code efficient and you'll be fine

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 TehOne · Feb 25, 2014 at 05:42 PM 0
Share

Thanks for the info. I have been looking at an object pool to manage the game objects that I will be dynamically placing in the scene. I found a few decent ones on github that gave me a good starting place. As for the floating point errors, I was thinking that would be caused more by my character/camera/object position and not by the amount of objects in the scene. If I keep moving to the right forever, my x position will eventually be very high, and that is where I was thinking the floating point errors might start showing up.

avatar image Regalith · Feb 26, 2014 at 03:31 PM 0
Share

your right about the floating point error, but if you build the game the way I explained, the character will never actually move. From how you explained your game you're making something like infinite $$anonymous$$ario. If that's the case, then you create a Dynamic array that's filled with platforms. Then you just iterate through the array and change the lateral position of every platform (just translate alone the x axis) based on player input. It'll look like the player is moving, but actually the platforms will.

avatar image TehOne · Feb 27, 2014 at 10:05 AM 0
Share

Ok, yeah, that was basically my original question. I was asking which is better, to move my player and camera or the platforms. I've seen it done both ways and just wanted to know the pitfalls of each. $$anonymous$$oving the player seems to have the floating point problem, but I was thinking it would be more efficient than moving a lot of other items (platforms, coins, obstacles, etc). In my $$anonymous$$d, moving 2 things (player, camera) just seemed more efficient than moving (potentially) a lot of things: platforms (made up of multiple sprites each); coins in groups up to maybe 30; obstacles etc.

avatar image
0

Answer by bionicartsmobile · Sep 20, 2020 at 03:30 PM

I would also like to know which is better.

For example, if I am moving an array of prefab platforms and resetting them to the right for an infinite runner... for a mobile device... does Unity or Memory have a harder time calculating the positions of every child of the prefab platform section?

Is it more performant to move the player? Or does Unity only calculate the Parent of the Prefabbed Platform Section? Does Unity spend more memory calculating the lighting when moving levels versus moving the player?

Performance-wise... which way is better/smarter for optimization on mobile?

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 bionicartsmobile · Sep 20, 2020 at 03:30 PM 0
Share

NooO!!! I always mess up the reply/answer. $$anonymous$$y bad!!

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

22 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

Related Questions

Assets/Scripts/PlayerController.cs(32,49): error CS0126: An object of a type convertible to `float' is required for the return statement 1 Answer

Performance issues with new version of Unity 0 Answers

Better Performance for 2D game 0 Answers

How to make wheel collider with Physics2D? 1 Answer

Best way to move a rigidbody 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