Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Skyrim style doors?

Discussion in 'Scripting' started by ATLAS-INTERACTIVE, Dec 21, 2014.

  1. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    We are creating a large scale game, meaning interiors in the same map are a big no-no for us, and we need a way to move the player between scenes, keep the controller's inventory and states, teleport them to a specific place (like the door) and for it to work the other way and position them on the "other side" of the door.

    Anyone have any ideas, any help would be greatly appreciated.
     
  2. toreau

    toreau

    Joined:
    Feb 8, 2014
    Posts:
    204
    You need to fill in the additional 1+ million "gotchas". :) Is this an MMO? Should the "outside world" still be running while inside a house etc.?
     
  3. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    :eek:
    No, this is not an online game, not sure how we would cope with that, considering the amount of detail we are putting in :D
     
  4. djweinbaum

    djweinbaum

    Joined:
    Nov 3, 2013
    Posts:
    533
    You could have system/player related gameobjects call DontDestroyOnLoad(). Then when you load your interior scene your player will remain in whatever state its currently in. If you want a loading screen you could have a special scene just for UI and load that one then immediately call LoadLevelAsync("MyInterior")
     
  5. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @djweinbaum I don't think that will be a viable solution, as it loads the player to their coordinates on the level they loaded from, meaning every room would have to be perfectly positioned in its scene, and vice versa.
    Others have suguested it before and we tried it but it didn't really suit the way we are building our map.

    We need something easy that can be setup a few hundred times if need be and relatively quickly, but adaptable instead of having a couple hundred slightly different scripts.
     
  6. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You would move the player to the correct position when loading a new scene.
     
  7. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Well, my first thought was actually something similar.

    I'd call DontDestroyOnLoad (and of course make sure everything does only spawn once, otherwise it should get destroyed e.g. the player character) and as soon as I enter somewhere, save the position and when the interior level is loaded, find the spawn object in the scene, get its transform.position and move the player to that position.

    When going back to the main world, just teleport the player back to the position you saved before. *edit and turn him around or something.
     
  8. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    @Suddoha This does sound OK, if I could place an object in the scene (infront of the door(either "side")) and grab the transforms from that each time that would be much better, I am a 3D artist myself and our only programmer is busy working on the character controller, I know this is asking a lot, but could you or someone else supply some working sample code for us to test out with?
     
  9. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Yes, that's what I actually meant. You'd place the spawnObject which represents the position in your main world. You may attach a script to it (or wherever your programmer thinks it may be best) and trigger your GUI (confirm button in order to enter) etc. When confirmed (in case you need to confirm at all), save the position and an appropriate rotation to some variables (or just use the players position directly - but i'd take the data from an object in order to avoid glitches, just place it appropiately in front of the door (outside).

    In every interior, I would then have a script which moves the player to the spawnObject in that scene. This could be assigned to a variable of the script or could be found during runtime - your choice. It allows to simply adjust the position by dragging the object around without touching code again. The only thing that would need to be done in every interior is creating the spawn object and placing it (plus the assignment when working with the inspector slots).

    Well, the rest is rather easy, have a trigger to allow you to quit again and reset the data so that you'll 'come out' where you 'entered'.

    Sorry that i don't provide some code, not much time, but I'm sure your programmer will come up with a good solution. Or someone has got the time to provide a working example.
     
  10. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    Thanks for clearing that up for me, I am very aware of the time it takes to add gameobjects to variable declarations in scripts, having done it almost constantly when we were working on the character controller artwork.

    I think this would be better if done like you said with an object placed where the player needs to be on either "side" and a script to move between the two, As we are using F as a use key (function), I probably wouldn't even need to use a GUI in that instance, just some printed text on the screen in the trigger to tell the player what to hit to use it, I can drag that bit out of our object grab script hopefully.

    Although I am hoping someone will be able to post something to get me started, our programmer is only part-time and currently working on another project as well (not for us) so he isn't available a lot of the time, I am OK at programming, I just usually need something to get me started with it.

    Have a good Christmas and New Year.