pls help is this a bug or a feature ? o.O

I was coding on movement for my sidescroller like Game. after I finished everything worked fine, except moving the ship past the point where it was when the Game started would make it invisible for some Reason.here is a Gif showing that : http://shadow.bplaced.com/gifs/wtf.gif

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour {

    public GameObject Player;
    public GameObject Player_Movement_Point;

    // Update is called once per frame
    void Update () {
        if(Input.GetMouseButtonDown(0))
        {
            Player.transform.parent = null;
            Player_Movement_Point.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.x));
        }

        if (Input.GetMouseButton(0))
        {
            if(Player.transform.parent == null)
            {
                Player.transform.parent = Player_Movement_Point.transform;
            }
            Player_Movement_Point.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.x));
        }
       
    }
}

can someone tell me what causes this ? :slight_smile:

btw, when I move it in the Editor it works, and when I use transform.position to tp it to the middle it doesnt work.

Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.x))

This could be your problem. You’re passing the mouse X position as the distance from the camera, so when the X value goes too low, your object is probably getting too close to the camera, or going behind it or something perhaps.

Try this:

Vector3 screenPosition = Input.mousePosition;
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(screenPosition);
worldPosition.z = Player_Movement_Point.transform.position.z;
Player_Movement_Point.transform.position = worldPosition;