How to instantiate a canonball's transform correctly

Bear in mind that my project is pseudo-3d Breakout. The orientation is 2d, though all the objects are 3d.

In short, I’ve got a cannon composed of a rotating base, an attached barrel, and a cube at the ‘mouth’ which I figured to use as a spawn point for the cannonballs.

My question deals with constructing the cannonball. If my cannon is rotated 30 degrees in the Y axis, what code should I use to correctly orient the canonball?

I know this is super simple, and I know I could probably reason it out, but I remember enough from my linear algebra classes to know that I need to make sure I do it right.

All you have to do is make sure the “cube” spawn point for the ball is facing the right direction, forward would be the z axis facing out. Then you don’t need to worry about the cannonball’s rotation, because you won’t use it. You will use the direction of the cube. Here’s an example assuming your cannonball is a rigidbody. And of course, make sure the cube is not a collider. You can use a collider but then you would have to use some IgnoreCollision, my way here just makes it easier. This example is in C#.

This code would go on the cube. I’ll have it add force to the ball once instantiated.

public GameObject cannonball;
Vector3 fwd;
float power = 10.0f;


void Update()
{
    fwd = transform.TransformDirection(Vector3.forward);
    if(Input.GetKeyDown(KeyCode.Space))
    {
        GameObject clone;
        clone = Instantiate(cannonball, transform.position, Quaternion.Identity);
        clone.rigidbody.AddForce(fwd * power, ForceMode.Impulse);
    }
}