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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to spawn at the door you used when changing scenes?

Discussion in 'Scripting' started by spartaboy300, Aug 9, 2015.

  1. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    I'm working on the main town of an rpg that has multiple buildings like shops and a town center. And I made a code that allows the player to go up to a door (where a trigger collision is) and press E to change scenes. Now my problem is that when the player leaves, they spawn at the start of the town no matter what building they come out of. So what is the proper way of making these changing spawn points? I've read about making a master game object that has a DontDestroyOnLoad script and using door IDs but I don't really understand how that works. Any help is appreciated! :) (I use C# btw)
     
  2. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    for me easiest would be to set positions of spawn points (town entrance, inn entrance, etc...) and when exiting store where from he exited, upon loading town scene it checks entering town location (from inn for example) and spawns/teleports player there. you can do something like manager and store he left from inn and dontdestroy so data gets to next scene, if that is what you are looking for
     
  3. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    This sounds like exactly what I'm looking for, but I'm confused on how to apply it. Is there a command to read and save what trigger he used? Then do an 'if' statement?
     
  4. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    you can define in town script or town manager spawn locations like (inn is at 25,30,60) and maybe even give some rotation (away from inn), then have manager with some int variable. When leaving inn store in int representation of inn lets say 1 represents inn, when loading town scene it reads 1 (you came from inn) and teleport/spawn player at spawn point of inn you predefined at start
     
  5. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    What is the reason you need to change scene?
     
  6. kittik

    kittik

    Joined:
    Mar 6, 2015
    Posts:
    565
    There's no reason to change scene. You could make a scene with the interiors and exteriors within it and the action of triggering door could 'teleport' the player to the building interior. transform.position is your friend.
     
  7. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    839
    it sure is, this is in my opinion one of the better ways, we had about 20 levels, which was 20 scenes, and went through this, and using a teleport type worked the best, because what can happen, when he appears in the other scene things can go missing, we never needed don't destroy, or load etc when using teleport...
     
  8. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    Ok I think I'm starting to understand
     
  9. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    This does seem more efficient and easier but I plan on the game being mobile, and since this is my first game I wasn't sure about the limitations of a phone. Do you think a scene like that would be to big for a phone?
     
  10. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    I
    if it is 3d i dont think it maters much as that is not rendered if far enough i think
    If 2d, it should not be problem if world is not too big or if you manage tiles of bigger world good enough.
    I alone dont prefer scenes ans if can i try to avoid it but for rpg with bigger world you would need more than one scene so why dont make new scene for inn also.
    Also first game open world rpg? Didnt you a little bit overshot?
     
  11. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    My first attempted game is a skyrim style open world party based adventure type simulation rpg with strategy and sim elements as well as fps style combat dungeon crawling and multi continent aspirations. I have no programming or 3d modeling background and am learning as i go busy with 3d moddeling now. Do you think i might been overshooting lol?.
     
  12. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    Well, I'm doing it in sections while doing the tutorial games to learn fundamentals. Plus my original "dream" is a VR rpg to play local multiplayer. So I'm using the Google Cardboard SDK. To make it easier though I'm trying to break the game up into two parts: environment and living things/systems. The living things/systems like NPCs and stuff is gonna be SUPER hard to learn from what I can tell. And it probably will be more towards instance gameplay than full open world.
     
  13. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    I'm right there with ya man
     
  14. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Ha i actually split my project into two projects one half has the enviroment housing etc the other the characters etc so yea maybe great minds think alike:D
     
  15. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    Lol hopefully this means we're doing it right then!
     
  16. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    How can it be wrong when it feels so right.
     
  17. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    You. You're right.
     
  18. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    it depends on your motivation but the fact is that after some time one, two or four weeks of creating and no product most people lose motivation and just quit. Creating smaller products you can finish will be best as you dont have to learn so much in such small time period, you will feel better for having done something and creating big project from start leaves you with tons of questions and ends with crushing big dreams. MAYBE you are part of that one small small precentage that start big and dont quit but still very small chance
     
  19. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    11 months so far nothing really to show for but found out a lot of ways how not to do things.Had to start over 3 times maybe more due to taking a incorrect approach .
     
  20. phoda

    phoda

    Joined:
    Nov 11, 2014
    Posts:
    384
    11 months of active development? wow i hope it succeeds, but just to mention that taking too long to create game is also bad, you may want to look for help if you need 11 more months.
     
  21. spartaboy300

    spartaboy300

    Joined:
    Jun 24, 2014
    Posts:
    16
    I see what you're saying and I really do need to be considering that, but I think the process I'm taking to make the game (which is basically breaking it into small parts and then putting them together to make one big product), allows for me to refresh my motivation quite a bit. Also, I think using VR when I test has a huge impact. I don't know what it is but it amazes me every time I test my game and get to see what I've added come to life :D it's just so satisfying.