- Home /
AddForce in z axis
Hi, i create my tank and i want shoot bullets from cannon. I have turret which rotate on Y-axis and in the turret i have empty gameObject whitch represent bullet position. When the bullet is fired, they are in the correct position relative to the position of the turret. But when i add to script this code to addForce:
bulletInstantiate.GetComponent<Rigidbody>().AddForce(transform.forward * _speedShoot * 40);
and turn turret to right side for example bullet is fired from front not from right side. I want to shoot on lacal z axis not from global z axis. Sorry for my english and thanks for advice.
Answer by guerre14 · Oct 15, 2020 at 09:57 PM
@andrejjelinek You have to make sure the bullet is looking exactly at the same direction than the turret when it rotates One thing I would do is to set the bullet as a child gameObject for the turret and ensure both have the same rotation when init, this way when the turret rotates the bullet will rotate as well, so when the bullet is shot it will be shot forward.