Hi all, not sure if anyone has ever experienced this issue but I’m trying to shoot a projectile out of a moving “parent” object. Both objects move off of rigidbody physics so I’m using addforce for the projectile. Whenever I move the “parent” object and turn while it’s moving then shoot the projectile, I instantiate the projectile, copy the projectile spawn position to the project’s position, copy the rotation of the “parent” to the projectile then add force to the projectile. It’ll shoot but I notice it moves in the direction of the momentum of the “parent” rather than straight forward from where it was created. I’m pretty sure this is just me not understanding how rigidbody physics works for adding force but if anyone has any ideas suggestions as to how to make the projectile move straight forward from where it’s created rather than copying the momentum of the parent I’d appreciate it greatly. My code for creating a projectile looks like this:
//create bullet
GameObject bullet = Instantiate(bulletPrefab);
//set location where bullet will spawn from
bullet.transform.position = bulletSpawn.position;
//set direction of the bullet
bullet.transform.rotation= bulletSpawn.transform.rotation;
//add force to the bullet
bullet.GetComponent().AddForce(bulletSpawn.forward * bulletSpeed, ForceMode.Impulse);
//destroy bullet after x time
Destroy(bullet, lifeTime);