I'm having a hard time grasping the concept of position in Unity.
Have a parent object (Player). On that player, I have a child object called "Gun". On the gun, I have a script to fire bullets. When I fire the bullets, it spawns to the left of the gun, and the player.
I've tried offsetting the bullet's position on spawn, but when I turn around, the location is incorrect (it's still not centered on the gun). I also have a feeling that the offset that I've tried is a hack, and that I've missed something somewhere.
My code for the firing script on the gun :
void Update()
{
if (Input.GetAxisRaw("Fire1") > 0)
{
var pos = transform.position;
print(pos.ToString());
var proj = Instantiate(projectile, pos, Quaternion.identity);
proj.transform.rotation = transform.rotation;
}
}
The only other thing touching the bullet, is my BulletController, a script on the bullet :
void Start()
{
rb = GetComponent<Rigidbody2D>();
//rb.AddForce(transform.forward * 100, ForceMode.Impulse);
rb.velocity = transform.up * 10;
}