Make empty Transform object switch side of player

Hi there,

I’m very new to C# and Unity and I’m making a 2D platformer as a means to learn the engine. Currently, I have player movement and projectiles set up. However, the sprite I’m using has been animated outside of Unity with the intent of having a projectile spawn point not at the center of the sprite (in other words, a bit in front of where the player is facing). My problem is, I can’t seem to find a way to make the Transform object hop over to the left side when I’m facing left and vice versa. The object is nested in my player object.

What is the best way to approach this? Intuitively, I’d just set the local x-coordinate to the negative of it’s current value, but I can’t seem to find a way to do this. If I pitch new coordinates to the ProjectFireLocation, they seem to reflect the world coordinates and go way off. Rummaging through the API, I suspect somehow InverseTransformPoint is involved, but then again the Transform object is already nested in my player object as mentioned earlier.

I’m attaching the code somewhat truncated:

public Class Player{

public Transform ProjectileFireLocation;

   privatevoidFireProjectile()
{

         if (_canFireIn > 0) {
          return;
         }

var projSpeed = newVector2 (ProjectileTravelSpeed, 0);

var direction = _isFacingRight ? Vector2.right : -Vector2.right;


var projectile = (Projectile)Instantiate (Projectile, ProjectileFireLocation.position, ProjectileFireLocation.rotation);

projectile.Initialize (gameObject, direction, projSpeed);

_canFireIn = FireRate;

}

Maybe this is a sign of me skipping too many steps in the learning process cause I’m anxious to get a playable build. Either way, thank you for your time and I appreciate any help!

Sincerely,
Dan

I feel very silly now. All I had to do was take a short break to figure it out. I just declared two Transform-objects instead of one and made a boolean to switch between the two depending on which direction the player is facing. I’m just gonna leave it on here in case some other noob like me has the same issue. Apologies!