Moving player – another way?

Updated on November 28, 2019 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 26, 2019

Hi all

I’m a silver surfer and I’m trying to keep young by knocking up a 2d top down game, just for my own personal fun. 

I have a main area, a town, with houses which the player can enter, where the player is then presented with an “inside”. 

To do this I have a player prefab in each scene. When the player moves over an object with a collider, the “inside” scene of that house is loaded, with another player inside, which can then be moved. When the player then goes outside, the main town is loaded, and, more or less, the player is moved to the correct position. 

This works more or less. I have some issues with the camera (long story), but other it’s OK. 

My question is, is there a better way of doing this? I’ve given up trying to async load the scene, then move the player object to that scene to a given location (either x,y or ontop of an empty object). I just couldn’t get the player object to move reliably, if at all. 

Are there other ways I should be looking at? Is this “best practice”?

Olly

  • Liked by
Reply
1 on November 26, 2019

Instead of destroying and making  a new player object for every scene, you could make the play a don’ destroy on load object, and just move them to the appropriate spot for the interior/exterior scene transition.

If you want to try async agin, what you could do, is have some area around the house that preloads the interior, and the door is just the trigger to switch the active scenes. Brackeys did a video about loading screens that shows you how you would be able to asynchronously load a scene, but not switch to it instantly.

 

Alternatively to both of those, you have the inter/exterior in 1 scene, just have the interior above/ below the exterior, and set the camera to only render far enough for whatever plane the play is on.

Helpful
on November 28, 2019

The idea of Mouledoux is correct. I also use the DontDestroyOnLoad method to translate the player between different scenes in our game.

I created a Pre-Load scene, where all game controllers and the player loaded first at game start and then tranlate between the desired scene.

 

Show more replies
  • Liked by
Reply
Cancel