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 russelldc · Feb 13, 2014 at 10:28 PM · movementplatformercontrol2.5dside-scrolling

Circular (Inside cylinder) World for 2d Platformer

I'm wondering what would be the best way to have a 2.5D side-scrolling platformer play out on the inside of a cylinder. So in a simple example, the character would be able to run all the way around the inside back to where they started.

I've thought about possibly having the character not move left or right but rather the cylinder rotate around them when pressing left/right, but wouldn't this cause problems with the camera?

Basically, is there some efficient way to restrict the character's left/right movement to a circular motion around the inside face of a cylinder world?

Comment
Add comment · Show 2
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 robertbu · Feb 13, 2014 at 10:34 PM 0
Share

I have a hard time visualizing a side-scrolling game in an enclosed pipe, so a visual (even a hand-drawn one) would be helpful. Having a game where the player runs down the inside of a pipe has been covered a number of times in the last year. Assu$$anonymous$$g the character movement is only on the inside of the pipe, you can use Transform.RotateAround() to rotate the character, or you can place an empty game object at the longitudinal axis of the pipe, make the player a child, and rotate the empty game object. Consider leaving the character at the origin and moving the pipe rather than moving the character.

avatar image russelldc · Feb 13, 2014 at 10:53 PM 0
Share

Sorry about that, I understand that it's hard to visualize; I'll draw up something soon. You said this idea has been covered many times in the last year? Do you have an example of this? Thank you!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by thinkyhead_ · Feb 27, 2014 at 11:17 AM

I just built a looping 2D/3D world recently, and I considered using a scheme like you describe with the inside of a cylinder, but I dropped that approach; it's too messy and involves too much computation to have things move in arcs. Instead, split your scenery into two or more pieces that are at least wider than the screen. Two pieces —each half the size of the world— is ideal. Attach a script to these scenery groups called "LoopingScenery." Then have all your game objects inherit from a class named "LoopingWorldObject" (or just attach it as a component). Then your scenery and game objects will move as needed according to the position of the main camera. Here's what these classes look like for my game, which uses a world 10,000 units wide and two scenery chunks that are each half the size of the world:

 public class LoopingScenery : MonoBehaviour {
 
   Transform T, mainT;
 
   // Manual Initialization, if needed...
   public void Init() { gameObject.SetActive(true); }
 
   // Initialization once in the world
   public virtual void Awake() {
     T = transform;
     mainT = Camera.main.transform;
   }
   
   // Move this object to the other end of the world as-needed
   void Update() {
     float diff = mainT.position.x - (T.position.x + 2500f); // 2500 = center of the chunk
     if (diff > 5000f)
       T.position += Vector3.right * 10000f;
     else if (diff < -5000f)
       T.position += Vector3.left * 10000f;
   }
 }
 
 public class LoopingWorldObject : MonoBehaviour {
 
   protected Transform T, mainT;
 
   // Manual Initialization, if needed...
   public virtual void Init() { gameObject.SetActive(true); }
 
   public virtual void Awake() {
     T = transform;
     mainT = Camera.main.transform;
     while (CorrectForCamera()) { /* do nothing */ }
   }
   
   // Move this object to the other end of the world as-needed
   public virtual void FixedUpdate() { CorrectForCamera(); }
 
   bool CorrectForCamera() {
     bool didCorrect = false;
     float diff = mainT.position.x - T.position.x;
     if (diff > 5000f) {
       T.position += Vector3.right * 10000f;
       didCorrect = true;
     }
     else if (diff < -5000f) {
       T.position += Vector3.left * 10000f;
       didCorrect = true;
     }
     return didCorrect;
   }
 }

NOTE: Since your gameObjects probably have to collide with the scenery, your particular solution will therefore need to involve one extra copy of the scenery chunks to ensure nothing falls through when the scenery is moved. Or, to avoid the extra scenery copies, you could devise a solution similar to this one which keeps each gameObject inside the same group as the scenery that it's closest to, changing its parent as it moves from one to the other. In that case, you just need to make sure the gameObjects have access to the scenery groups and check them against their positions rather than the camera.

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

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

20 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

Related Questions

How to make camera position relative to a specific target. 1 Answer

What is the problem here ?( move script, c#, basic, platformer) 0 Answers

Collision problem 1 Answer

jittery collisions 2d platformer 1 Answer

Can't change direction mid-jump 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