Hi I am making a space invaders style game in C Sharp and when I run the game the bullet takes the position of my player object but it is spawned significantly in front of the player. how do I get the bullet to fire from the same position player ship.
I have included the code associated with the bullet function below.
The first section of code is taken from my player class script.
void Update ()
{
horizontalMovement = Input.GetAxis ("Horizontal");
//verticalMovement = Input.GetAxis ("Vertical");
if (Input.GetAxis ("Vertical") > 0 && canFireBullet) {
FireBullet ();
}
}
void FireBullet ()
{
canFireBullet = false;
GameObject.Instantiate (playerBulletPrefab, transform.position, Quaternion.identity);
audio.PlayOneShot (bulletFireSound);
StartCoroutine (ResetCanFireBullet ());
}
IEnumerator ResetCanFireBullet ()
{
yield return new WaitForSeconds(1f);
canFireBullet = true;
}
This section of code is take from the bullet fire class script.
public class bulletfire : MonoBehaviour {
private float movementSpeedMultiplier = 1.5f;
void FixedUpdate ()
{
transform.Translate(Vector3.forward * movementSpeedMultiplier);
}
}