How to make projectile cannon

I’ve tried a lot of things but they failed, the projectile works but making it spawn out of the end of the cannon and having it move that direction failed. How would you make this work?

The cannon part rotates towards your mouse position in the game.

The empty gameobject is parented to the gun and is positioned on the end of the cannon

3462363--274680--Capture.PNG

Can you explain a bit more what you mean with “The projectile works”? What kind of projectile do you currently have, and what aspects are “working”?

There are many different ways to set this up. One way would be:

  1. Create a projectile GameObject and save it as prefab. (Make sure it looks in the same direction as the turret when it is not rotated)
  2. In the script that recognizes your mouseclick for the firing, add a reference to the prefab projectile GameObject
  3. In the Firing code, spawn the projectile with Instantiate
  4. When you create the projectile instance, make sure to give the projectile the same local rotation as your turret
  5. Add a script to the projectile gameobject that simply moves the gameObject along the forward vector

You could also take a look at the Unity tanks tutorial: Tanks - Unity Learn
IIRC those tanks did not have rotating turrets, but you could still look at how they did the projectile creation when firing.