Player not spawning at right position

Hi,

My player is not spawning at right position. I am facing this problem only in 1 scenario.

Scene 0, Portal A to Scene 1, Portal A → works fine
Scene 1, Portal A to Scene 0, Portal A → works fine

Scene 0, Portal B to Scene 1, Portal B → works fine
Scene 1, Portal B to Scene 0, Portal B–> player spawns at a different position than the spawn point.

I tried recreating portal and spawn positions at different locations thinking that the terrain might be causing some local problem but that is not the case.

Please help.

Thanks,
Shaktimaan

First things first, are there any error messages when you transition from 1B to 0B?
Post a screenshot of your Portal B along with the inspector and we’ll see if there is anything obvious.

Thanks @Brian_Trotter for the quick response!

  • I am not getting any error during the transition
  • In the screenshot, I have highlighted portal and the position where player is spawning

Thanks for the help!

In your scene 1, are both Portals at the root of the heirarchy?

I’ve had the same issue where 3 out of 4 transitions would work, while the fourth one would transport me to a pretty random location, between the scene’s original player location and the portal’s spawnpoint.

What I did, that might work for you, is the following:

In UpdatePlayer(), after getting a reference to the player, I disabled the NavMeshAgent (before changing the player’s transform) and enabled it again at the end of the function, like so:

image

And those two extra lines did wonders for me. Hope it works for you too :confused:

1 Like

Thanks @HyperLucario, that did the job for me as well!
Now, I am wondering what is going behind the scenes which affects only one transition and not the others?

1 Like

Glad to hear that!

I’m not exactly sure what causes this, I tested a few things and noticed that if the destination portal’s spawnpoint si too far away from the initial position of the player in the destination scene, Unity places the player somewhere in-between the two points. If I had to guess, the NavMeshAgent might have some ways to prevent instant travel across large distances, but that is pure speculation. I’d love to know the real answer too!

@HyperLucario , your observation is right. I noticed it too that the spawn position was somewhere in the middle of the initial position and the spawn position.

I believe temporarily disabling the NavMeshAgent is mentioned in the course videos. This is because without disabling it, moving the player can be inconsistent.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms