Rotation of the bullet

Hello there!

I have already changed the rotation of my arrow, but on another topic, Nina mentioned “SpriteRenderer.flipX” how can I use this? I have already searched on google but I have no clue about it

void OnFire(InputValue value)
{
    if(!isAlive) { return; }
    
    if(value.isPressed)
    {
        myAnimator.SetTrigger("Shoot");
        if(myRigidbody.transform.localScale.x == 1)
        {
            Debug.Log("Right");
            Instantiate(bullet, gun.position, transform.rotation);
        }
        else{
            Debug.Log("Left");
            Instantiate(bullet, gun.position, Quaternion.Euler(0f, 180f, 0f));
        }

    }

}
1 Like

Not quite sure what you are asking, but your rotation doesn’t look right. In 2D, we usually rotate on the z-axis, not y

Instantiate(bullet, gun.position, Quaternion.Euler(0f, 0f, 180f));

The flipX just flips the sprite, but does nothing to anything else. So, in this crude example, an arrow

<-- would become --> but the transform and everything else will remain the same so moving the transform based on its local vector will still move it in the same direction

You can use it like this

var bulletInstance = Instantiate(bullet, gun.position, transform.rotation);
var spriteRenderer = bulletInstance.GetComponent<SpriteRenderer>();
spriteRenderer.flipX = true;

// or just
Instantiate(bullet, gun.position, transform.rotation).GetComponent<SpriteRenderer>()).flipX = true;
1 Like

Thanks! @bixarrio that was exactly what I was looking for. :handshake:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms