2

撃ったときに弾丸がスポーンする場所

やあ、なんらかの理由で、弾丸が指定した場所に出現しません。スポーン ポイントは銃身の端にあり、弾丸をインスタンス化するときに変換位置と回転を取得しますが、銃よりも高い位置 (はるかに高い位置) にスポーンします。私が持っているコードは次のとおりです。

    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");
    }
}

ヘルプ :)

4

1 に答える 1

1

弾丸の原点がモデルの中央にない場合があります。

于 2016-05-22T15:41:47.980 に答える