c# – Unity. Instantiate object in Local Space

You can use Transform.TransformPoint

Transforms position from local space to world space.

like e.g.

public void PlayEffect()
{
Instantiate(slashEffect, wielder.transform.TransformPoint(new Vector3 (0, 1, 1)), wielder.transform.rotation) ;
}


This takes the 0, 1, 1 as a vector in the local space of your wielder meaning, if you would create a child object and set this to be its local position, this is where your object will be spawned in world space.

Note that this takes also the scaling of the wielder into account!

If you do not want to take the scaling into account rather use the Quaternion operator * like

public void PlayEffect()
{
Instantiate(slashEffect, wielder.transform.position + wielder.transform.rotation * new Vector3(0, 1, 1), wielder.transform.rotation) ;
}


What this does is using the world space offset vector 0, 1, 1 but then rotates that vector without chaning its magnitude according to the wielder rotation in the world space.