- Home /
3d Platform tutorial respawn wrong location
Hi, I recently worked my way through the Lerpz tutorial. I loved it, and was inspired. So I went on to create a new level (as suggested). I created a terrain, and then used the assets from the tutorial to create a different layout for Lerpz. All has gone well, except for one thing. The player respawns in the wrong location - not on the respawn platform.
I placed three Respawn point, named them, and set the initial respawn as the first one. But Lerpz gets dropped off to the side of my newly created layout. I added some debugger logs to the script and I can see that the proper location is actually being passed, but somehow Lerpz is ending up elsewhere.
Anyone have any idea what would be causing this? I have tried replacing the respawn points, and reconnecting everything, but I get the same result. If I manually set the player position as the location that is passed in the script, he is right where he's supposed to be. I am running out of ideas.
@Yanger_xy if you need to ask for clarifications on a question, please use the question's comment area. The answers section should be reserved for solutions.
@ruralbrewer like Yanger said, we'll need to see code before we can offer much help.
Wow. Sorry. I guess I will just keep working it out myself. I thought maybe someone who was familiar with the tute might have an idea.
Answer by Yanger_xy · Jun 21, 2011 at 03:28 PM
I haven't looked the Lerpz tutorial.Can you post some code?
Answer by ruralbrewer · Jun 21, 2011 at 05:38 PM
If you haven't gone through the tutorial, then I don't think you are going to be much help. Even more of a point is that, being new to this and having just gone through the tutorial, I wouldn't be sure what code to post. Other than adding debugger log statements, I have not changed the code at all, and it works fine in the original scene. The issue could be with the player, the respawn platform, the configurations in the inspector, the levelStatus code, the respawn code, perhaps even the terrain that I added. I certainly can't post the entire project. But thanks for responding.
Please post clarifications either as comments or edits on your original post until you're able to (i.e. hit the karma req's) post comments on solutions directly. The answer space should be reserved for solutions.
Answer by ruralbrewer · Jun 25, 2011 at 01:10 PM
Just in case someone runs into this same issue, I figured out the cause. Lerpz is getting respawned in the right place... however, he retains his "momentum". So, for example, when Lerpz is killed by a copper, the enemy hit knocks him off of his current position. So when he is respawned, he is still moving. In my case, he was being respawned onto a relatively small platform, so by the time he reappeared, he was off the edge. He then just fell to the ground (the terrain that I added).
I tried different methods to stop his motion as part of the death script, but I was unable to accomplish this. My hack fix was to simply add a yield (1.6) to the beginning of the death script. This gives enough time for Lerpz to come to stop again after being hit. This works well enough for my purposes here.
I, of course, plan on learning a better way to deal with this in the future, but I have plenty of things yet to learn in Unity, and for now, I can move on.