transform.position isn't worldspace

I have an empty game object for a spawn point. I’m trying to get a sphere to spawn where it is but it spawns in a completely different spot.

I tried using transform.InverseDirection and transform.Direction and neither of them worked. I even tried doing this but it still spawned in a completely separate location.

public IEnumerator EnergyBallAttack()
    {                           
        Vector3 spawnPos = handShootPoint.transform.position;
                                                                                                               
        Rigidbody rb = Instantiate(energyBall, spawnPos, handShootPoint.transform.rotation).GetComponent<Rigidbody>();
                                                
        rb.isKinematic = true;                                                                             

        rb.transform.parent = handShootPoint.transform.parent;
        rb.transform.localPosition = handShootPoint.transform.localPosition;

        Vector3 savePos = rb.transform.position;

        rb.transform.parent = null;

        rb.transform.position = savePos;

        rb.transform.localScale = Vector3.zero;
        rb.transform.DOScale(5f, 0.7f);

        yield return new WaitForSeconds(0.75f);

        rb.isKinematic = false;

        rb.AddForce(handShootPoint.transform.forward * cannonForce * 6, ForceMode.Impulse);
    }

As soon as you parent something, the position reads out as local coordinates.

Also, parenting a Rigidbody isn’t generally a good idea. If you want it attached, use a Fixedjoint.

I managed to fix it by making the parent of handShootPoint an empty game object with a reset transform.

transform.position is always world-space

edit: i can’t read, and thought the bullet was set to have the bullet shoot point as a parent. oops! my entire explanation is now irrelevant :face_with_spiral_eyes:

1 Like

Actually you were pretty correct, the parents were the problem. The parent of handShootPoint had a wonky position rotation and scale and that was messing it up.

Hm, that’s interesting. It’d certainly make sense if they had a non-uniform scale.