torsdag 2 mars 2017

The curious case of teleportation.

this week I worked on how the player would be transported through the room.
at first we just wanted to delete the door so the player could walk freely between the rooms. This showed itself to be quite bothersome.

To explain how our game works. We're designing a game called "Bullet_hack" wich is about a spy trying to infiltrate a compan to get information about them. You play as the spy and try to hack doors to get to the main server.
You hack the doors by playing a shooter game where you destroy the enemy spawn points to
progress to the other room.

since we change scenes to initiate the hacking game deleting the door will not work since the loadscene(); function recreates everything in the scen you load. So deletion is of the table.
So i decided to try to see if i can get the player to teleport between the rooms upon interaction with the door. This was a huge failure on my part.
I tried using PlayerPrefs to save the players position and change it whenever a level was loaded. In hindsight, this would have caused me a metric ton of problems  and work in the future since it meant that i would need to specify exactly where the player would spawn after every level.

So after a week of frutration I asked Håkan for guidance. Five minutes later the telportation was fixed. He told me that all i ned is a static string and several empty gameobjects called "Spawn_point" (with a number at the end) and tie the players position to the Spawn point and the string as a tool to specify wich spawn point to teleport the player.
This worked and I still slam my head into walls or any other hard surface I find because it's so simple and i didn't think of it at all. In my defence i tried to find answers online, but everything i found pointed me in the direction of PlayerPrefs and, strangely, they also pointed out how bad they are for teleportation and in general. This should have been a big tip off that whatever I would potentially do with the PlayerPrefs it wouldn't be worth the effort when there's simpler options available.
The lesson I learned this week; in the future I will try to ask the teachers if I have problems with anything instead of trying to force google to tell me.

1 kommentar:

  1. Hello Tobias!

    This was a very interesting post. I think it is a great explanation of stating a design goal, realizing the challenge it poses and then attempting to work towards a solution. From your description of your original approach of how to achieve the teleport, I can clearly understand your line of thinking and why you thought the PlayerPrefs route would solve it.

    One of the fantastic resources we have is the Google. It often leads us to wonderful solutions and sometimes drags off into the woods where we get lost forever. It is that difficult thing of knowing what answer you are looking for so you can ask the correct question to find it.

    In the end the PlayerPrefs system didn't work for your solution but did you use it somewhere else in your game? What actual benefits does it provide and how is it useful? Did you explore the Unity Docs to learn more about it or just read through forum posts?

    I know that it can be eternally rewarding to work through a problem and solve it on your own. We have an incredible resource here at the school and that is the instructors. I communicate with them quite often because I consider them to be another form of Google. If I choose not to use them, when they are freely available, then it makes no sense at all. I hope you take advantage of their experience sooner in the future. Thanks for the informative post on how not to use PlayerPrefs! Keep up the great work!

    SvaraRadera