How can I change the rotation of an instantiated object?

This is for a 2D orthographic project (top down).

I’m trying to instantiate a bullet from a gun.

Then when the health is at max, I want to instantiate a bullet in the opposite direction also.

For some reason, this current script is only instantiating a second bullet to the right.

if (PlayerHealthController.instance.healthAtMax && LevelManager.instance.hasSwordShotA)
                    
{
                        
Instantiate(swordToFire, firePoint.position, firePoint.rotation);

                        
if (LevelManager.instance.hasSwordShotAUpgrade)
{

 Instantiate(swordToFire, firePoint.position, Quaternion.Euler(firePoint.rotation.x, firePoint.rotation.y, firePoint.rotation.z));


}
}

Obviously I’m misunderstanding how a quaternion.euler is supposed to be read, but I need a little guidance. Can anyone advise? Thanks!

Bumping ^
Thx!

variable A = Instantiate(YOUROBJ);
A.rotation = YOURROTATION.

Do you have a picture of what “instantiating a second bullet to the right” means? My guess is that your bullets pushed each other outside of their collision boxes, but it’s hard to tell from the description.

Sure! Here’s an example:

https://imgur.com/a/NRN7QnD

You can see how the second bullet, one from this:

 Instantiate(swordToFire, firePoint.position, Quaternion.Euler(firePoint.rotation.x, firePoint.rotation.y, firePoint.rotation.z));

is going only to the right.

Yeah but how do I write that rotation for “YOURROTATION”? Wouldn’t it be the same issue? I need to figure out how to instantiate and changing only one axis angle.

So by this I guess you mean you want to shoot one backwards?

I believe you can just do Quaternion.Inverse on your firePoint.rotation.

EDIT: the above might flip the sprite upside down too so that may not be wanted. In that case you can use your firePoint.forward, reverse it and use look rotation:

Vector3 backwardsDirection = -firePoint.forward;
Quaternion reverseRotation = Quaternion.LookRotation(forward: backwardsDirection, upwards: Vector3.forward); //assuming forward is towards the screen
Instantiate(swordToFire, firePoint.position, reverseRotation);

Some basics about Transform. After reading this, you might be able to pose more specific questions in a way we can help.

https://discussions.unity.com/t/587912/18

It sounds like your project might be 2D; the same concepts apply from 3D. You can set the position AND the rotation of any object once it’s been instantiated. You have to decide what position you want, and what rotation you want. There are methods on Transform, on Vector3 or Vector2, and on Quaternion classes which can calculate those values.

Hmm… I tried this but appear to be getting the exact same result. The new projectile instantiates only to the right.

It might help if I share how I’m moving the bullet once it’s instantiated?

            theRB.velocity = transform.right * speed;

I’m going to assume that ‘transform’ refers to the projectile’s own transform, and that clearly isn’t right. Get the direction you fired the original project at, and put a - in front of it. That’s the direction you send the other projectile in.

Man I figured this out! The issue is the bullet script was in update, so the rotation was never happening quite right. So essentially I had to create a bool protected method in that script and call it while passing a bool condition. Worked it out, I’m just dumb (face palm).