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;
}