Prefab Rotation After Instantiating

Fixed. Found that you can create an empty GameObject and place the projectile as a child then create a prefab from that with the correct rotation. I wish you could simply change the rotation of the x, y or z axis on an object without rotating the object.

I’ve spent a lot of hours on this issue, researching, asking questions and watching videos.

There is a an Empty GameObject attached to the ship on all four turrets. These are called turretLB, turretLT, etc (left bottom, left top). These GameObjects are attached to the script in the inspector. This is the instantiation script as it currently exists:

Instantiate(laserLBPrefab, turretLB.position, turretLB.transform.rotation);
Instantiate(laserLTPrefab, turretLT.position, turretLT.transform.rotation);
Instantiate(laserRBPrefab, turretRB.position, turretRT.transform.rotation);
Instantiate(laserRTPrefab, turretRT.position, turretRT.transform.rotation);

On the prefab there is a script to move the projectile forward:

transform.Translate(transform.forward * maxSpeed * Time.deltaTime, Space.World);

I had to add Space.World to get it to move forward in the correct direction, though I am confused as to why you use World coordinates and not Local.

The issue is that the prefab projectile comes out at a 90 degree angle pointing straight up. Changing the rotation of the Empty GameObject (turretLB, turretLT, etc) has no effect.

Any suggestions? I’ve tried dozens of things to fix this.

which prefab is that attached to, the projectile? what does the instantiation code for the projectile look like?

Im a very news in programming but should not you do turretLB.rotation?

well usually the code attached to the projectile just says “go forward”, which makes it totally dependent on the initial orientation it was instantiated with. I’m guessing a little that the prefab is being instantiated with a reference to it’s own rotation not that of the spawn point given that it’s not changing when the spawn point is altered.

It’s in the post.

Fixed. Found that you can create an empty GameObject and place the projectile as a child then create a prefab from that with the correct rotation.

I wish you could simply change the direction of the x, y or z on an object without rotating the object.