Creating a start point in 2d game

I am trying to create a start point for my game, so that when the player switches scenes they are placed where I want them to be to make it seem more real. I am having a problem however, after following some instructions, I wrote a script to do this and upon playing the game the camera zooms close to the ground as if the player is invisible or behind the scene. I can walk around and interact with the world but the character isn’t there. I’ll post the script and hopefully we can figure this out, I will also attatch the file. Thanks in advance!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This checks player position when loading into new levels or scenes

public class PlayerStartPoint : MonoBehaviour {

private PlayerControl thePlayer;
private CameraControl theCamera;

public Vector2 FaceDirrection;

// Use this for initialization
void Start () {
thePlayer = FindObjectOfType ();

thePlayer.transform.position = transform.position;
thePlayer.LastMove = FaceDirrection;

theCamera = FindObjectOfType ();
theCamera.transform.position = new Vector3 (transform.position.x, transform.position.y, theCamera.transform.position.z);

}

// Update is called once per frame
void Update () {

}
}

2950470–218745–PlayerStartPoint.cs (777 Bytes)

Is the player on a Z Level that makes sense? Can you try changing his Z Level to bring him into focus? Is he spawning in the heirachy?

Well not seeing your two scene I can’t tell, but I see you keep the same position.z for your camera when switching scene.

Should it be?

Maybe your ground doesnt have the same Z on both scene, and thats why it appear different when you switch from one another?

I have changed the z level but that doesnt seem to help.

I have changed the z on both scenes to see if that is the issue but the problem still stays.

You should first go to the scene and place everything as it should be. Your camera should show your player and this will give you a reference point of where things should be.

Then when you switch scenes, see where things “end up” after. This should help you track down what value is putting your player in the wrong place. Double click the player. Where are they? Are they in the ground, in the air? Are they on the wrong z coord. Try to adjust them so they appear back in view of the camera (while in play mode so you know)

Also, is this a save system you’re trying to load from? For a 2d game you should normally be able to place your player and camera in the scene and just load the scene and not have to move anything and you’d be fine.

1 Like