• 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
4
Question by amirabiri · May 22, 2012 at 09:07 AM · shaderphysicsworld

How to create a "wrapping" world in Unity?

I am trying to create a "wrapping" ("rolling" / "repeating" etc) game world. In other words when a game object goes beyond the borders of the world I flip its location to the opposite edge.

My problem now is that I want to make this behavior more smooth. This means that for an object that is partially crossing the world border, two things must happen:

  1. The part of the object that is beyond the border must render on the other side (the game is in top-down view).

  2. The part of the object that is beyond the border should collide with other objects on the other side.

A good example to explain what I mean is to think of the "Star Control" games (if you are old enough like me to remember them...).

I have achieved #1 by using additional cameras that do not clear the buffer and have a limited layer mask. However I think that this is somewhat inefficient? Is there a better way to do this? I looked into using shaders but am not sure if this is the right answer? Or is there something else I've missed?

I do not have a solution for #2 yet. I was thinking of using joints and started looking into the custom joint (as the basic ones obviously weren't built for this scenario). I still haven't fully got my head around how the custom joint works. Anyway the question is if this is the right direction, or is there something better that I've missed?


Edit: Perhaps an image will help... :-)

alt text

wrapping world.png (24.7 kB)
Comment
Add comment · Show 14
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 Lo0NuhtiK · May 22, 2012 at 11:06 AM 0
Share

Like Asteroids or Unitroids you mean?

avatar image amirabiri · May 22, 2012 at 12:37 PM 1
Share

Yes exactly

avatar image amirabiri · May 24, 2012 at 11:14 PM 1
Share

Any ideas?

avatar image Eric5h5 · May 24, 2012 at 11:24 PM 0
Share

Unitroids uses 4 duplicate objects, where 3 are offset in a rectangle the size of the screen, and parented to the "real" one.

avatar image amirabiri · May 24, 2012 at 11:33 PM 1
Share

Yes but Unitroids doesn't do physics simulation on these objects does it? These are just sphere trigger colliders moving about.

For rendering purposes I wonder which is preferable - multiple cameras or duplicate objects?

avatar image Eric5h5 · May 24, 2012 at 11:52 PM 0
Share

It does physics, but only on the parent. The other 3 objects have colliders, but since they are parented to the main object, the main object gets collision events.

avatar image amirabiri · May 25, 2012 at 12:06 AM 0
Share

Yes I understand but what I mean is that it doesn't do a full physics simulation as in complex objects floating around. It's just 4 spheres.

In my case these are complex objects, the colliders are mesh colliders and the collisions affect them in a more complex way than a simple sphere collider is affected by collisions in Unity. The colliders themselves are free to rotate, and their rotations and angular velocity change based on collisions.

If I connect 4 meshes together the whole structure must have its rotation frozen otherwise the offset objects will not stay at their offsets as the whole structure rotates. But if I freeze the parent structure, I loose the whole point of the object being free to rotate.

avatar image Eric5h5 · May 25, 2012 at 12:17 AM 0
Share

In Unitroids, the rotation of the parent is copied to the children, and the position is set appropriately every frame. So the parent does do a full physics simulation. The only reason for the parenting is so that the compound collider acts as one, otherwise it might as well be 4 separate objects. I do think using some camera tricks would be simpler overall, if you can get it working...I recall getting something like that only sort of working, so I went with the multiple-objects thing in the end.

avatar image amirabiri · May 25, 2012 at 12:32 AM 0
Share

I don't see how this would work without screwing the physics simulation. When an Offset object is hit and receives torque for example, how is that change in physics state applied to the parent? furthermore if the whole structure is allowed to rotate then it doesn't behave correctly.

The asteroids in Unitroids don't react to collisions so this isn't really helping.

avatar image Eric5h5 · May 25, 2012 at 12:38 AM 0
Share

Well, yes, when an asteroid is hit, it's destroyed and replaced with other asteroids, so having to deal with the results of collisions isn't an issue there. Other than that, the initial rotation and movement are done by adding torque and forces as usual. But that is why I said that using some camera tricks ins$$anonymous$$d would be simpler overall....

avatar image amirabiri · May 25, 2012 at 12:45 AM 0
Share

As I've explained in my question above, I have solved the problem of rendering with additional cameras. However the physics problem remains (collisions). Camera's can't solve this problem.

The rendering problem can also be solved with offset objects. I'll be happy to know what the pros or cons of each method are. However so far I don't see how offset objects will help with collisions, unless I've missed something.

avatar image runonthespot · Aug 01, 2013 at 01:42 PM 0
Share

4 copies wouldn't be enough if wrapping up and down as well as left/right.

avatar image runonthespot · Aug 01, 2013 at 01:43 PM 0
Share

(consider where an object is crossing through a corner

avatar image slog · Mar 11, 2014 at 12:54 AM 0
Share

Hi, wondering how far you got solving this problem? Im tackling the exact same thing now (but in 3 dimensions)

$$anonymous$$y current thinking is that the collisions problem actually isnt a problem, provided you only have 1 real copy of the colliding objects ( the copies being represented by extra cameras ), and provided you use the same collision meshes to test for world-edge intersection as you do for physics collisions. I guess there is the chance that 2 objects might collide with opposite boundaries at exactly the same time, and then they'd appear to move through each other, but that seems like the only caveat...

$$anonymous$$y simple tests are working fine on this assumption, just wondering if that's held true for you or how you ended up solving it?

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by MrVerdoux · Dec 12, 2013 at 09:39 AM

The real solution is to make it real: make a toroidal universe! Of course that would cause strange physics, a lot of work... but can you imagine the result? No tricks there, your world would really be wraped!!! You would be my hero :)

alt text

http://en.wikipedia.org/wiki/Doughnut_theory_of_the_universe

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 Mikael-H · Dec 12, 2013 at 10:06 AM 1
Share

Damn you now I simply must make a game with a donut shaped world...

avatar image
2

Answer by p.hufnagl · Dec 12, 2013 at 08:51 AM

1)I had a simelar problem and fround 2 solutions

-)Use a secound camera translated exactly 1 map size away and let them draw over each other. They even move automatically right if you parent them to the player picture of cameras

-)Divide your map into subtiles. when the player comes close to an edge take the last tile behind away and put it in front of him (better solution i think)

2)I can think of one solution:

Make collider just outside your Map (so they get triggered when something showes over the edge). Then you instanziate a Gost object of it on the other side of the map (position - map size).


cameras.png (4.6 kB)
Comment
Add comment · 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
1

Answer by adept22 · May 22, 2012 at 11:03 AM

I would create a extra instances of your "world" and tile them, as soon as you move from one i would delete the instance of the "world" you just left and create a new instance in the same direction you went to replace...

If that makes any sense?

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 amirabiri · May 22, 2012 at 10:25 PM 1
Share

I understand what you are describing but I don't quite see how it will solve the problem, perhaps I've missed something?

The problem is that an object can interact with "ghosts" of other objects, i.e copies of other objects from the other side. However when a collision occurs I need the original object's physics to be affected, not just its ghost.

In other words I need the results of collisions and other physics events on the ghost to be applied to the origin object ins$$anonymous$$d of the ghost.

avatar image adept22 · May 23, 2012 at 11:41 PM 0
Share

Is there a known fixed number of "collision" objects that will be interacted with? or are they randomly spawned? are they multiple instances of the same object. ie asteroids or all unique objects

avatar image amirabiri · May 24, 2012 at 11:05 PM 1
Share

There is a limited number of objects. They are randomly spawned initially.

avatar image
1

Answer by runonthespot · Dec 12, 2013 at 09:53 AM

Technically, the answer to this is going to require a few things:

  1. 8 copies of the object (complete with rigidbodies, colliders etc) that can wrap, placed half a screen above, beneath, left, right, above left, above right, beneath left, beneath right.

  2. All of those objects to be connected to the central object with joints / constraints. You basically need a rigid joint that holds the objects positions relative to each other (which will also transfer forces applied to one to all of them), and the objects themselves rotations need to be jointed together (not just synced), so that angular velocity applied to each object is applied to all other objects. (perhaps code that, on collision, each frame, syncs the angular velocity?)

  3. Probably some code to ensure that objects outside of the view have their colliders disabled.

It's the physics aspect that makes this so difficult.

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 amirabiri · Jun 17, 2014 at 07:58 PM 0
Share

In the end (more than a year ago...) this is what we went with. With the exception that I didn't use joints, but simply updated the parent physic's properties on collision. It worked well. I even tested comparisons with normal objects and the "linked" objects (via code) behaved identically.

avatar image dr_vlat amirabiri · Aug 18, 2016 at 12:10 PM 0
Share

Hi! I'm trying to figure out in the same issue (wrapping and collisions), like you did couple of years ago. $$anonymous$$ay I ask, how did you distributed collision data across the 3x3 object grid?

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

13 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

Related Questions

2D 360 degress platformer example needed 0 Answers

Best Way to Implement an Exaggerated Horizon Curve to 3D Endless Runner? 0 Answers

How to correct build a ShaderGraph PBR Shader [LWRP] 0 Answers

How to force the compilation of a shader in Unity? 5 Answers

Warp Shader? 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