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 EvanesceExotica · Apr 29, 2014 at 07:24 PM · 2dside-scrollingbuildings

Entering 2D Buildings?

Hello,

I'm trying my hand at a 2D side-scrolling/platformer action rpg in Unity2D (I know, I know), and I was wondering what's the best way to deal with buildings in 2D. I find entering buildings easy to envision in a 3D world, but when it comes to the camera being locked to stay mostly on the x and y axis, I can't quite wrap my mind around it. Here's an example of what I would like from Muramasa: The Demon Blade: https://www.youtube.com/watch?v=SAHME_7mizg#t=1920


I understand that triggers are needed but I'm confused about where the interior of the building would be, so to say. I'd like the characters to run in front of the facade of the building with a trigger over the front door allowing them to press whatever button to enter. The inside of the building would be a side-view too, like in the example I showed above.

Should it be a new scene entirely? (I imagine that could make things way too complicated and slow for a lot of buildings). Or should I just build it separately somewhere in the current scene and have the trigger at the front door of the facade teleport them to inside the building, where a fixed camera would be enabled? I'm planning future indoor levels where there are several rooms (sort of like a hotel corridor), so having possibly so many separate rooms could make things difficult.

I was also toying with the idea of having only a few different variations of the interior of buildings per level decoration-wise, and just randomizing what spawns inside of them.

Thank You for the Help, Eva

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

Answer by Xevoius · Apr 30, 2014 at 02:51 PM

I think this all depends on how large your rooms are. In my game, I have one master room chamber scene with doors to all the other rooms that are scenes of their own. Every room is a level and can be made up of smaller room areas with doors that teleport the player around this same room (scene).

I maintain a collision list on the player object. This keeps all the objects that the player is currently colliding with so that I can iterate over it when the player presses the action button.

When the player collides and OnTriggerEnter2D is called, the object is added to the list and when the player stops colliding OnTriggerExit2D, the object is removed from the list. This allows me to give the collision some logic say when there is a pickup object that is in front of the door and the player is colliding with both the door and the pickup object.

As far as graphics goes, start using the SpriteRenderer Sorting Layers to make sure objects appear on top of one another how you want them. They are named layers and make things easy to organize on the screen as opposed to adjusting their Z value.

One other important note: OnTriggerEnter2D and OnTriggerStay2D and OnTriggerExit2D seem to be bugged in the current release. I still use them in my project with some workarounds that I am hoping I will be able to remove sometime soon.

http://issuetracker.unity3d.com/issues/ontriggerenter2d-called-too-many-times http://issuetracker.unity3d.com/issues/ontriggerstay2d-is-called-not-properly

Cheers.

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 GEWLAR · Apr 30, 2014 at 01:13 PM

For entering a building you could use something like this:

Attention this is only pseudocode

 public Vector3 Teleportposition
 void OnTriggerStay (collider other)
 {
     if( collider.tag == "Player" and input.getkey("w"))
     {
        //Go into house
        LastPosition = other.transform.position
        other.transform.position = Teleportposition
        
     }
     
 }

I would use there OnTriggerStay because this gets called every frame. So while you stay in the Trigger and press the key the Teleport Code gets called.

I think a Scene for every room is to much. Especially if you have several rooms in a building. So I would create the room by itself and then teleport the player to the new location.

I recommend to save the Players-Lastposition in a Variable. I would save the Variable in a Script on the Player. If you only have one Player in the Game you can make this Variable a static Variable.

Hope this is helpful for you.

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

21 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

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

2D Animation does not start 1 Answer

Side scroller - rotate object towards player. 1 Answer

How to make wheel collider with Physics2D? 1 Answer

2d side scroller projectile/firing weapon script help needed. 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