Problem with Instantiate() and position

Hi everyone. I’m not sure this thread belongs here, as it’s my first time searching for help this way. Also, I’m not an English native speaker, so my language may not be at its best. Having made these premises, I need help with a little bug that I apparently can’t manage to fix on myself: I am working on a 2D platformer and the player has certain abilities, one of which is cloning himself for a short period of time pressing the P key. The problem here is that the clone doesn’t instantiate in the position it should (a bit ahead of the player), and instead, it instantiates always in the same point near (0, 0)

Here’s the code I used for it, I will appreciate every tiny bit of help cause I tried all I know and nothing works

public class magic1 : MonoBehaviour
{
    public Transform firePoint; //this is where the clone should appear
    Vector3 firePointCurrentPos;
    public GameObject clonePrefab; //the clone
    bool hasCloned = false; //used for recharging time

    void Update()
    {
        firePointCurrentPos = firePoint.position;
        if (Input.GetKeyDown(KeyCode.P) && !hasCloned)
        {
            hasCloned = true;
            StartCoroutine(Clone());
        }
    }
    IEnumerator Clone()
    {
        GameObject clone = Instantiate(clonePrefab, firePointCurrentPos, firePoint.rotation);
        clone.tag = "cloned";
        yield return new WaitForSeconds(10f);
        Destroy(clone);
        yield return new WaitForSeconds(5f);
        hasCloned = false;
    }

Check fire point position before instantiate. Is it correct?
Check clone position exactly after instantiate. Is it correct?
If both are correct, then it’s something with your code. Maybe your forgot to remove some players scripts when made clone prefab.
Check all scripts that have access to clone, maybe something is moving him to (0, 0).

1 Like

OHH thank you so much I totally forgot other code could access its position and when I went to check the code that made it move I found that it is actually moving it to (0, 0)!! How could I have been so dumb XD

1 Like