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


問題描述

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

我正在製作一個簡單的 Unity 2D 遊戲。其中有三個遊戲對象 ‑ 1) 地面(長矩形) 2) 玩家(正方形) 3) 硬幣(圓形) 目前我是在所有三個上使用對撞機。這些碰撞器幫助玩家保持在地面上,當玩家與硬幣碰撞時,我會增加分數。 但問題是,當玩家與硬幣碰撞時,它的行為就像硬幣是物理物體一樣,它會停止玩家。我不想要這個 我希望當玩家與硬幣碰撞時,它們之間沒有物理交互 我嘗試了一件事 ‑ 將玩家和硬幣中的碰撞器切換為 isTrigger,但在在這種情況下,玩家和地面以應有的方式進行交互(玩家從地面跌落)。


參考解法

方法 1:

Make the interactable objects triggers. That way, you can interract with them, without obstracting your path. To do that, go to the collider Component on the inspector and check the "Is Trigger" checkmark. Then, go to your scripts and instead of the event OnColliderEnter use the event OnTriggerEnter

(by void_117Rhach)

參考文件

  1. How to have collision detection without physics in Unity? (CC BY‑SA 2.5/3.0/4.0)

#game-physics #unity3d






相關問題

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?)







留言討論