簡體   English   中英

2D Bullet於2018.2統一傳播

[英]2D Bullet spread on unity 2018.2

我實際上是在嘗試統一2018的2D動作游戲。我想在用槍射擊時做子彈傳播,我需要指定在鼠標光標上射擊槍。 我在網上搜索了所有內容,幾乎找不到解決方案。 因此,我在教程中編寫的代碼無法按我希望的方式工作,因為項目符號會散開並朝着光標移動,但會沿錯誤的軸旋轉並產生錯誤。

void Shoot()
{
    Vector3 fireDirection = spawnPoint.right;

    Quaternion fireRotation = Quaternion.LookRotation(fireDirection);

    Quaternion randomRotation = Random.rotation;

    fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, maxBulletSpreadAngle));

    nextFire = Time.time + 1f / fireRate;
    Instantiate(Balle, spawnPoint.position, fireRotation);
    ballesRestantes--;
}

或保持展開,沿良好的軸旋轉,但不要跟隨光標,而是直接向前射擊。

 void Shoot()
{
    Vector3 fireDirection = spawnPoint.forward;

    Quaternion fireRotation = Quaternion.LookRotation(fireDirection);

    Quaternion randomRotation = Random.rotation;

    fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, maxBulletSpreadAngle));

    nextFire = Time.time + 1f / fireRate;
    Instantiate(Balle, spawnPoint.position, fireRotation);
    ballesRestantes--;
}

我希望有人能幫助我,對不起,英語不好,我是法語。

這個想法不是在光標所在的位置發射子彈,而是放置一個偏移值,並在Random.Range(-offset,offset)的幫助下,獲得接近光標位置的隨機值並使子彈移至那些位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM