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)