I want to be able to shoot a projectile from a weapon mounted on a vehicle. Right now I am able to do it but only in front of the vehicle. I managed to rotate the weapon to the direction the mouse is facing, but the projectile still goes straight.
I believe that the issue is that the velocity of the projectile is the problem here. Right now I have it like this:
if (playerShooting || NPCShooting) { if ((timer >= cooldown) && hasEnergyAvailable()) { timer = 0; GameObject intantiatedProjectileContainer = Instantiate(projectileContainer, transform.position, transform.rotation) as GameObject; Rigidbody instantiatedProjectile = intantiatedProjectileContainer.GetComponentInChildren<Rigidbody>(); if (playerController) { instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed + transform.root.GetComponent<PlayerController>().getZSpeed())); } } } Where speed is the projectile speed and it's added to the vehicle speed.
I thought that this should shoot forward but with the parent rotation, can someone tell me what I'm missing here? Thanks!
gun.transform.forwardand use that, but I am not able to help you more than that if you do not provide more code :D \$\endgroup\$