public class GunShoot : MonoBehaviour
{
public Rigidbody Bullet;
public Transform BulletSpawn;
public int damage = 10;
public float bulletVelocity = 500f;
public ParticleSystem mf;
public PlayerMovement playerMovement;
public Rigidbody Tank;
public Transform Gun;
public float recoil = -600f;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("left ctrl"))
{
mf.Play();
Shoot();
}
}
void Shoot()
{
Rigidbody bulletInstance;
bulletInstance = Instantiate(Bullet, BulletSpawn.position, BulletSpawn.rotation) as Rigidbody;
bulletInstance.AddForce(BulletSpawn.forward * bulletVelocity);
Recoil();
}
public void Recoil()
{
Tank = GetComponent<Rigidbody>();
Tank.AddForce(Gun.transform.forward * recoil);
}
}
So here is what im trying to do, its a tank, the turret can rotate independently of the body id like to add a recoil to the body but in the opposite direction of the turret. so im not sure how to add force to the tank but use the transform direction from the gun