Gun rotation is opposite of player rotation, how do i do the fix? (how to set rotation to 0, 0, 0?)

In my 2d top down shooter, im trying to add weapon pickups. however, theres a bug where the weapons rotation is the reverse of the player because i have it like it just parents the gun to the player so when the gun pickups rotation is 0, 0, 0 and the players rotation is say 0, 0, -35, the rotation of the gun is 0, 0, 35 and its rly annoying
how can i fix this? heres my code for weapon pickup

using UnityEngine;

public class Pickup : MonoBehaviour
{
    private Inventory inventory;
    public GameObject itemButton;

    public GameObject icon;
    public GameObject itemInGame;
    public Transform itemPosition;
    public Transform itemHolder;
   
    // Start is called before the first frame update
    void Start()
    {
        inventory = GameObject.FindGameObjectWithTag("Inventory").GetComponent<Inventory>();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if(collision.CompareTag("Player"))
        {
            for (int i = 0; i < inventory.slots.Length; i++)
            {
                if(inventory.isFull[i] == false)
                {
                    //Item can be picked up and added to inventory.
                    inventory.isFull[i] = true;
                    Instantiate(itemButton, inventory.slots[i].transform, false);

                    //Swap the icon with the actual item and position it to the item position
                    icon.SetActive(false);
                    itemInGame.SetActive(true);
                    transform.position = itemPosition.position;
                    transform.SetParent(itemHolder);
                    break;
                }
            }
        }
    }
}

i think i have to set the rotation of the gun to 0, 0, 0 but i dont know how to do that (:P)

i know its somethign to do with euler angles ;-;

transform.localRotation = Quaternion.identity;

thanks

it says it cant convert from type vector3 to quaternion ;-;

Are you using Quaternion.identity, or something else?

ok i figured it out

this is how i fixed it:
transform.localRotation = Quaternion.identity

Then your error is coming from a different line of code. That line has only Quaternions and Quaternion variables in it.

no no, i fixed it, its working fine now, i was just syaing how i fixed it

1 Like