统一子弹产卵
Unity bullet spawn
Where the bullet spawns when I shoot
嗨,由于某些原因,我的子弹不会在我告诉它的地方产生。
生成点在我的枪管末端,我在实例化子弹时采用了它的变换位置和旋转,但它生成的位置比枪高(高得多)。
这是我的代码:
Animation anim; // Gun animation when shooting
AudioSource gunSound; // Gun sound when firing
public Rigidbody bullet; // I get the rigidbody of the bullet that will be spawned
public Transform spawnPoint; // The position of where it is supposed to spawn
void Start()
{
anim = GetComponent<Animation>();
gunSound = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetButtonDown("Fire1")) // If the left mouse button is clicked
{
Rigidbody bulletInstance;
bulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as Rigidbody; // This is where I don't understand why?!?!
bulletInstance.AddForce(spawnPoint.forward * 1000f);
gunSound.Play();
//anim.Play("GunShot4");
}
}
求助:)
子弹的原点可能不在模型的中间。
Where the bullet spawns when I shoot
嗨,由于某些原因,我的子弹不会在我告诉它的地方产生。 生成点在我的枪管末端,我在实例化子弹时采用了它的变换位置和旋转,但它生成的位置比枪高(高得多)。 这是我的代码:
Animation anim; // Gun animation when shooting
AudioSource gunSound; // Gun sound when firing
public Rigidbody bullet; // I get the rigidbody of the bullet that will be spawned
public Transform spawnPoint; // The position of where it is supposed to spawn
void Start()
{
anim = GetComponent<Animation>();
gunSound = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetButtonDown("Fire1")) // If the left mouse button is clicked
{
Rigidbody bulletInstance;
bulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as Rigidbody; // This is where I don't understand why?!?!
bulletInstance.AddForce(spawnPoint.forward * 1000f);
gunSound.Play();
//anim.Play("GunShot4");
}
}
求助:)
子弹的原点可能不在模型的中间。