shoot projectile from weapon


i have a character class that can pickup a weapon object in the game and create an instance of that weapon so that it is attached to a point/socket of his body, the character/player can shoot a projectile so the character class will use the Weapon Class to instantiate a projectile Weapon.Shoot() again the weapon class uses a point/socket where to spawn the projectile.

the problem here is the weapon is in the correct position in the game when you move around but if you shoot the projectile it is not spawned where the Projectile socket is in the world.

instance of the weapon in the character script:

            GameObject weaponClone;
            weaponClone = Instantiate(Weapon.gameObject, WeaponSpawnSocket.transform.position, 
            Quaternion.identity) as GameObject;

            weaponClone.transform.parent = gameObject.transform;

instance of the projectile in the weapon script:

        projectileClone = Instantiate(ProjectileObject.gameObject, 
        gameObject.transform.position, ProjectileSpawnSocket.transform.rotation);


thanks in advance,

Honestly @quintendc, I can’t see anything wrong with that implementation. It might be how you setup the gameobjects and scripts, but there is no obivious mistakes in your code.
For completion sake, I will attempt to write a small controller/Gun/Player script below that I believe can work. Wish me luck.

// Attach to player object
public class PlayerController: MonoBehaviour {

	PlayerInteraction pi;
	void Start () {
		pi = GetComponent<PlayerInteraction>();
	// This is the prefab that is stored in the assets folder
	public GameObject Weapon;
	// Call this to equip the Gun
	public void EquipGun () {
		GameObject weaponClone = Instantiate(
				transform // Instantiate it directly under its parent to avoid weird positioning effects.
			) as GameObject;
		pi.gc = weaponClone.GetComponent<GunController>(); 

// Attach to player
public class PlayerInteraction : MonoBehaviour {
	public GunController gc;
	void LateUpdate() => HandleShooting();
	void HandleShooting () {
		// First check for null
		if (gc == null)
		// Check for input
		if (Input.GetKeyDown(KeyCode.MouseButton0)){

// Attach to Weapon
public class GunController : MonoBehaviour {
	public GameObject projectTile;
	// We instantiate it at Vector3.Zero because position 0, 0, 0 relative to the gun is its center.
	// We don't have to worry about world position
	public void Shoot () => Instantiate(projectTile, new Vector3(0, 0, 1), Quaternion.Identity);

Try putting the shoot code in LateUpdate()… instead of in Update() by then… the weapon should have finished all it’s movement positioning in the world, and the projectile should come out of the correct position.