In my project I’m expecting my projectile to fire from my mouse controlled cannon out of the barrel towards the direction of it at the same speed, but I got this.
Script is included.
In my project I’m expecting my projectile to fire from my mouse controlled cannon out of the barrel towards the direction of it at the same speed, but I got this.
Script is included.
At first glance everything seems to be set up correctly. From how it behaves in your video, I would assume something is messing with the empty GameObject you use to get your velocity / direction vector for the projectile. It looks like as soon as the tank starts turning, it is being rotated as well. Can you enter playmode, drive the tank around a bit, rotate the turret a bit and then check if the empty GameObject is still pointing in the correct direction? If it is in the wrong place, you need to find out what causes this.
As a workaround you could also use
projInstance.velocity = transform.forward * 3f;
This should just push the projectile in the “forward direction” from the turret transform, so it should fire where the turret is currently looking at.
I fixed it already, I got confused with unity’s vector system. Had to remove * 3f
projInstance.velocity = m_Transform.position - transform.position;