Aim ruined when changing launcher position.

Sorry for the abstract title, but basically I have a gun that shoots balls, and i had to reposition the balls to shoot from the muzzle of the gun to the following:

   //Fix the launch position of the rocket 
   var launchPos : Vector3 = transform.TransformDirection(new Vector3(0.1, 0.1, 1.1));

Works good, 1 big problem… The ball will no longer shoot where the crosshair is located!(which is obviously in the middle of the screen) If i go far back, and shoot, the ball will hit to the left of the crosshair, and if im close, the ball will hit to the right of the crosshair. How do i fix this without changing the Vector3 to (0,0,0) because I need the balls shooting from the muzzle AND be accurate to the crosshair?

Thanks.

Can you give a bit more detail about what is going on in the game? It’s not obvious how you decided on that particular vector or how that relates to the way the ball is supposed to be launched.

Sorry, the script im using is the same one from the FPS Tutorial one, i just tweaked it a little, heres the updated full gun script:

var launchPos : Vector3; 
var projectile : Rigidbody; 
var initialSpeed = 60.0; 
var reloadTime = 0.5; 
private var lastShot = -10.0; 

var muzzleFlash : Renderer; 

var reloadRealTime = 5; 
var bulletsPerClip = 15; 
static var bulletsLeft : int = 15; 
static var clipsLeft : int = 60; 
static var SubtractClips : int = 0; 

var isReloading : boolean = false; 

var fireRate = 0.05; 

private var nextFireTime = 0.0; 

function LateUpdate() { 

   if(Input.GetButtonDown("Reload")  clipsLeft >= 1  isReloading == false  bulletsLeft < 15) 
   Reload(); 
   } 
   
    if (Input.GetKeyDown("2")) { 
            muzzleFlash.enabled = false;
   }    
    
function Fire () { 

   if (bulletsLeft == 0  clipsLeft >=1  isReloading == false) { 
     Reload(); 
     return; 
 } 

   // Did the time exceed the reload time? 
   if (Time.time > reloadTime + lastShot  bulletsLeft > 0) 
   { 
    
    //Fix the launch position of the rocket 
   var launchPos : Vector3 = transform.TransformDirection(new Vector3(0.15, 0.1, 1.15)); 
      //var launchPos : Vector3 = transform.TransformDirection(new Vector3(0.3, -0.1, 2)); 
   
    // create a new projectile, use the same position and rotation as the Launcher. 
    var instantiatedProjectile : Rigidbody = Instantiate (projectile,transform.position + launchPos, transform.rotation); 

    // Give it an initial forward velocity. The direction is along the z-axis of 
    // the rocket launcher's transform. 
    instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, initialSpeed)); 

   // Ignore collisions between the rocket and the character controller 
   Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider); 
   lastShot = Time.time; 
   FireOneShot(); 
   } 
} 

function FireOneShot () { 

         audio.Play(); 
            audio.loop = true; 
			muzzleFlash.enabled = true; 
			
//decrease bullets by 1. 
   bulletsLeft--; 
      //gun reload in time 
   if (bulletsLeft == 0  clipsLeft >=1  isReloading == false) { 
     Reload(); 
    } 
	
	if (audio) 
         { 
            audio.loop = false; 
         }
      // We didn't, disable the muzzle flash 
      if (muzzleFlash.enabled ){
           yield WaitForSeconds(0.05); 	  
         muzzleFlash.enabled = false;
    }
}

function Reload (){ 
if (!isReloading) 
{ 
isReloading = true; 

SendMessageUpwards("setEnableWeaponSwitch", false); 

//   Wait for reload time first - then add more bullets! 
yield WaitForSeconds(reloadRealTime); 

   // We have a clip left reload 
if (clipsLeft > 0){
         SubtractClips = 15 - bulletsLeft;
		 clipsLeft = clipsLeft - SubtractClips; 
		 if (clipsLeft < 0){
         bulletsLeft = bulletsLeft + SubtractClips; 
		 clipsLeft = 0;
		 }
		 else if (clipsLeft >= 0){
         bulletsLeft = bulletsLeft + SubtractClips; 
		 }
    }

   SendMessageUpwards("setEnableWeaponSwitch", true); 
   }
   isReloading = false; 
}

static function GetBulletsLeft () { 
   return bulletsLeft; 
} 

static function GetClipsLeft () { 
return clipsLeft; 
}

Basically, as i change the axis (X,Y,Z) of the bullet(or rocket) basically doesnt hit were the crosshair is, but hits a little bit to the right (because i changed the position of the rocket shooting from the muzzle of the gun to the right)

Im not sure how to make it accurate to the crosshair, or basically im not sure how to make the rocket shoot straight according to the crosshair without changing the axises to 0,0,0.

You gotta rotate the object that you’re instatiating from so that the instances of it (the rockets) are going to fire towards the crosshairs at some point down the range. Say, 20 yards for example.
Basically you have to sight it in with a rotation.

Oh, makes sense, so what would be the code to make the projectile rotate?

Try simply rotating the object that the rocket is instanced from with the rotation transformer in the inspector panel.
If the object is being propelled along the z axis then you simply point the Z axis towards the target, since it’s a local z axis.

if, however, you have multiple weapons and you change them from time to time, then maybe this wont work. You would probably have to control the rotation with a script every time you shoulder the rocket launcher?? I am not sure about that but I think there’s a transform.rotate command that would help.

Ahh thats quite confusing lol, but ill see what i can do and ill get back to you…

for now just try rotating the object your script is attached to and see if you can change the direction your rocket is fired.