Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)


問題描述

Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)

所以,我有一個問題。我是一個團結的初學者,我想創建一個高爾夫遊戲。我可以編寫 C# 代碼,並且我在 3D 建模方面具有基本水平。我的問題是我不知道統一編碼是如何工作的。我的想法是一個類似於 Golf It 的系統,如果你按下鼠標左鍵,你有一個球桿會出現,然後它會獲取鼠標的 y 軸並將球桿綁定到該軸。一旦你擊球,它就會利用球桿的速度並將球傳送到高爾夫球上。物理在高爾夫中並不是那麼好,因為不管你打得多重,你都不能讓球飛起來。因此,我想實現一些逼真的高爾夫物理。(我在讀高中,因此我可以計算物理計算)。

我希望有人更有經驗,至少能給我一些如何解決這個問題的想法。已經謝謝了:)

順便說一句。我已經嘗試搜索教程,也自己嘗試過,但沒有得到任何有用的結果。但我至少已經建模了一個球桿和球,還有一個小高爾夫球場。

如果這有幫助的話,我想為高爾夫球編寫一個腳本,等待高爾夫球桿的衝動(是的當然不行)。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class controller : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
      if (collision.gameObject.name == "golf_club")
        {
            rb.velocity = new Vector3(Collision.impusle, 0, 0);
        } 
    }
}


參考解法

方法 1:

Welcome new user. Don't use Update. Unity has many functions for when "a collision happens".

https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

You'll have to become really familiar with all those.

I suggest at first get familiar with using the physics engine, you'll be surprised how well it works for golf.

Later you can write your own physics (use a coroutine). You'll still likely use colliders only as triggers when you do that. You'll have to learn all about that too.

Be aware that it can take ~ 1,000 hours of work to become familiar with the basics of Unity.

(by lorinloewe4444Fattie)

參考文件

  1. Unity Golf game physics and movement controller (CC BY‑SA 2.5/3.0/4.0)

#game-physics #unity3d #C#






相關問題

Android AndEngine:簡單的精靈碰撞 (Android AndEngine: Simple sprite collision)

Box2D - 收集硬幣 (Box2D - collect a coin)

LibGDX - 只有可拖動的運動 (LibGDX - only draggable movement)

Swift 2 中的遊戲 - “touchesBegan”? (Game in Swift 2 - "touchesBegan"?)

SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)

2D 平台遊戲:為什麼讓物理依賴於幀率? (2D platformers: why make the physics dependent on the framerate?)

基於脈衝的物理 - 在輕物體上堆疊重物體 (Impulse based physics - Stacking heavy object on light object)

建造一堵提高速度統一的牆 (Make a wall that boost speed unity)

Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)

在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)

向前和橫向球員運動 (Forward and Sideways Player movement)

如何在 Unity 中進行沒有物理的碰撞檢測? (How to have collision detection without physics in Unity?)







留言討論