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 electrobunny · Oct 22, 2014 at 01:40 PM · scroller

2D side scroller with loop the loop

For my first unity project, I have built a side scroller/platformer using the unity 2D subset. I would like to introduce a looped track as in the picture below:

alt text

The noob question: Must I use 3D objects to implement this loop? Obviously the car and track have to have different Z positions when entering and exiting the loop. Since the 2D colliders seem to ignore Z position come to think of it, perhaps the loop itself can be 3D colliders. Can anyone suggest a simple way of handling this special case in my otherwise 2D game?

looptheloop.png (23.0 kB)
Comment
Add comment · Show 4
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 electrobunny · Oct 22, 2014 at 03:26 PM 0
Share

Yes, this is good, thanks. I guess only the track segments that cross each other must have their enables toggled.

avatar image Dimling · Oct 22, 2014 at 03:36 PM 0
Share

Yes, that sounds like a good solution! Please give the answer a thumb up if you found it helpfull :)

avatar image electrobunny · Oct 22, 2014 at 06:16 PM 0
Share

I'd be happy to... can you convert your comment to an answer? I do not have this option, possibly because I am a newb here.

avatar image Dimling · Oct 22, 2014 at 07:25 PM 0
Share

done! :) dident know myself it was possible so thanks :)

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Dimling · Oct 22, 2014 at 03:19 PM

Not sure if this is a good way, works at least :P

When you set a texture as Sprite you can define what layer to be at. You can for instance have the front track to be at layer 2 while the lower part of the loop is layer 1. This will then place the layer one behind layer two as displayed on your picture. The problem now will of course be the collision. But with help of some simple code you can for instance remove and add collision based on the current position of your cart.

Code to remove or add collision:

  collider.enabled = true;
 

Hope this helps

Comment
Add comment · Show 6 · 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 electrobunny · Oct 22, 2014 at 08:18 PM 0
Share

I implemented this with one catch... maybe it is a separate problem. I start with a disabled collider2d on the "exit ramp". Then when the vehicle leaves the "entrance ramp" I used your suggestion and enabled the collider on the exit-ramp. I also tweak with the vehicle's gravity a bit to make sure it stays relatively stuck to the top of the loop.

But my problem is, I would also like a Collider2d w/Trigger+Script on the exit ramp to un-tweak the vehicle's gravityScale. For now, I am simply putting that trigger on the section of platform after the exit ramp.

avatar image Dimling · Oct 22, 2014 at 08:52 PM 1
Share

I am sorry, not sure if I understand the question. Why can't you add this to the exit ramp?

avatar image electrobunny · Oct 22, 2014 at 09:02 PM 0
Share

$$anonymous$$aybe a separate problem... but when a collider is setup as a trigger, it no longer uses physics (objects pass through it). If I add a rigidBody2d, well now I need to disable and enable it (which I am not sure I can).

avatar image Dimling · Oct 23, 2014 at 07:25 AM 0
Share

Sorry for late answer!

If the cart is touching the ramp, physically, you might use OnCollision2D ins$$anonymous$$d of the trigger functionality.

Unity Documentation: OnCollision

Then you can for instance write like this:

 void OnCollisionEnter2D(Collision2D coll) {
         if (coll.gameObject.tag == "Exit Ramp")
             UnTweak();       
     }

avatar image electrobunny · Oct 23, 2014 at 10:56 AM 0
Share

I guess this is noob stuff... I was triggering collisions from the perspective of the terrain, but doing it from the Player (vehicle) is best for things that affect the vehicle. I'd give you another thumbs up if I could, thanks. :)

Show more comments
avatar image
0

Answer by Tepei · Oct 22, 2014 at 06:32 PM

You could use this

http://docs.unity3d.com/ScriptReference/Physics2D.IgnoreCollision.html

The tricks is wheen a ignore collision is done; then you want back the physics to works between the object, you have to deactivate the object and reactivate it in the same frame; that reinitialise the collision..

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

2D Autoscroller Glitches 0 Answers

In sequence position game objects 1 Answer

Created Material Shows Dark Sprite 1 Answer

Hiding specific areas of unity2d layers. 0 Answers

unity2d cannot create if gravity level 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