[2D] How to instantiate laser when player rotates?

Hey everyone!

So I have this code:

    Instantiate(_laserPrefab, transform.position, transform.rotation);

And laser appears here:
alt text
Then I try to make the laser match the tip of the spaceship, and do this:

    Instantiate(_laserPrefab, transform.position + new Vector3(0, .7f, 0), transform.rotation);

And I get this when x axis is 0:
alt text
But… when player rotates… something like this:

alt text

Obviously laser is rotating but not attached to the spaceship.

Is there some method that I’m not aware of that will adjust laser not only in rotation, but also position relative to the spaceship?

Thanks for the help!

Hi, you could create an Empty GameObject in your Player as a child at position (0, 0.7, 0) and then create a new variable in your script like:

public GameObject LaserSpawn;

Then you drag and drop the object in the variable to assign it.
Your script will become:

Instantiate(_laserPrefab, LaserSpawn.transform.position, LaserSpawn.transform.rotation);