Help to make Weapon firepoint rotation match the players facing direction with scale x -1

Hello, I have been struggling for days trying to solve this with a lot of different methods with no luck.

I have a gun script that takes a Transform[] FirePoint; and uses that transform to instantiate and rotate bullets. My problem is that my character uses Scale X to flip left and right so when he is facing Right all the bullets instantiate in the right direction but when he is facing left bullets go backwards. see gif:

133980-bullets-go-wrong-directionright.gif

133979-bullets-go-wrong-direction3.gif


I’ve put an example of my weapon script below to show how I am instantiating bullets. I’ve tried a lot of things like getting the facing direction of my character with transform.root but everything just kept making the script super cluttered and hacky.

void Update() {
            float ShootControlThrow = CrossPlatformInputManager.GetAxis("Right Trigger");
            if (ShootControlThrow > 0f) {
    
                foreach (var position in FirePoint) {
                        var projectileBody = Instantiate(projectilePrefab, position.position, transform.rotation);
                        projectileBody.velocity = position.right * projectileSpeed;
                    }
                }
            }
    
        void OnDrawGizmos() {
            Gizmos.color = Color.red;
            foreach (var position in FirePoint) {
                    Gizmos.DrawRay(position.position, position.right);
            }
        }
    }

If someone has an idea of how I can change this line to make the Y of the FirePoint to 180 or something I would greatly appreciate it. This has been stumping me for many days.

var projectileBody = Instantiate(projectilePrefab, position.position, transform.rotation);

Was able to make it work with help from Ymrasu and RobAnthem. I needed to capture the X scale of player holding the weapon to make a proper rotation and also use that scale to multiply the velocity so if the scale was ever -1 (meaning facing left) then multiply that by the projectilespeed to send it in the opposite direction if player is facing left.

Here is the new code that fixes the aim direction if anyone else has this problem.


void Update() {
float ShootControlThrow = CrossPlatformInputManager.GetAxis(“Right Trigger”);
Transform holdingEntity = transform.root;
holdingEntityScale = holdingEntity.localScale.x;
if (ShootControlThrow > 0f) {

        foreach (var position in FirePoint) {
            Quaternion rotation = (holdingEntity.localScale.x == 1) ? transform.rotation : Quaternion.AngleAxis(transform.eulerAngles.z + 180, transform.forward); 
            var projectileBody = Instantiate(projectilePrefab, position.position, rotation);
            projectileBody.velocity = position.right * holdingEntityScale * projectileSpeed;
            }
        }
    }