• 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
1
Question by SirTimmyTimbit · Feb 04, 2011 at 09:37 AM · scenetilerepeatcityseamless

How do I make a scene tileable?

Hello everyone!

I'm trying to create a city in Unity. I don't want to spend a lot of time on the prototype.

I was wondering if there is a way to assemble a tileable chunk of the city and repeat the opposite edge on the fly if the player approaches an edge. The tileable part would probably be a few city blocks long and wide. This is just to give the player a sense of a never ending city without building one.

I've searched around the questions and LoadLevelAdditive() seems like what I am looking for. Do I just load the scene and as the player reaches one edge of it load the same scene again adjacent to current scene? How would I position it?

Thanks!

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

Answer by runevision · Feb 04, 2011 at 09:52 AM

I'm not sure LoadLevelAdditive is the best approach here, since it doesn't handle positioning and it would also mean that your city just keeps on growing.

Instead I would suggest to have 4 instances of the tile block active from the beginning in a 2x2 grid.

A B *

C D

When the player (*) approaches the right side of the 2x2 grid (for example the right side of tile B), move the two tiles at the left (A and C) over on the right, i.e. move them a distance of 2 tiles, effectively shifting the grid by 1 tile:

B * A

 D   C

Same for the other 3 directions. For example, if the player then moves up and appraoches the top of the 2x2 grid, shift the bottom two tiles up.

Before:

* B A

 D   C

After:

    D   C
      *
    B   A

This way you can keep the player within your grid and never need more than 4 tiles active at a time.

Note that this method also works for bigger grid sizes. You could have a 3x3, 4x4, or even 10x10 grid of tiles that constantly shift the rows and columns at the edges of the grid to keep the grid approximately centered around the player.

Update - Technical Implementation Hints

Demonstrating a working solution in code or pseudo-code is beyond the scope of this answer. With a solid understanding of two-dimensional arrays it's not too hard.

If it seems too tricky, I'd suggest to first start with the simpler problem of doing it in 1D: Have a 1D array of active tiles, for example along the X axis.

The "potential world" would be like this

A   B   C   D   E   F   G

And the instanced list would hold X number of those (for example 3):

[C] [D] [E]

If the player moves sufficiently to the right, the whole world is shifted. It would work like this:

The tile in the first cell is destroyed:

[ ] [D] [E]

The first cell copies the tile reference stored in the second cell:

[D] [D] [E]

The second cell copies the tile reference stored in the third cell:

[D] [E] [E]

The new tile is created and stored in the third cell:

[D] [E] [F]

Now the world is shifted by one.

When shifting the other way, the process needs to be done from right to left instead.

Extending this to 2D is not really different - if the process above is for one row in a grid, it just needs to be repeated for each row. Then when shifting vertically, the same procedure is done for a column and repeated for each column.

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 Jesse Anders · Feb 04, 2011 at 10:18 AM 1
Share

Yup, exactly what I suggested in the OP's cross-post to the forums: http://forum.unity3d.com/threads/76635-How-do-I-make-a-scene-tileable. (@The OP: When posting to both UA and the forums, it's nice if you can cross-link the posts so that people don't duplicate their efforts in answering.)

avatar image SirTimmyTimbit · Feb 04, 2011 at 09:25 PM 0
Share

Sorry about that, I'm a total newb :)

avatar image AnotherTimmyTimbit · Mar 17, 2011 at 08:09 AM 0
Share

I posted a follow up as a solution below. Can't login with SirTimmyTimbit for some reason. I'd really appreciate your help again :)

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to make a seamless city ? 1 Answer

Multi-tile city builder 0 Answers

I've done something wrong in the tiling, any ideas? 1 Answer

How to repeat a scene in unity3d. 1 Answer

Snapping models 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges