You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中OnTrigger与碰撞未被检测的问题求助

碰撞检测失效:投射物与敌人碰撞无响应

我知道这个问题已经被提过很多次,但自己还是没找到解决方案。需求是实现枪械发射投射物,当投射物碰到敌人时执行对应函数,但Debug Log始终没输出“has Collided”。

投射物相关脚本

iceShard 碰撞处理脚本

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

public class iceShard : MonoBehaviour
{
    private IEnumerator changeSpeed;
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Enemy"))
        {
            Debug.Log("has Collided");
            changeSpeed = ChangeSpeed(other.transform.GetComponent<Enemy>().enemySpeed);

            StartCoroutine(changeSpeed);
        }

    }
    private IEnumerator ChangeSpeed(float enemySpeed)
    {
        enemySpeed = enemySpeed / 2;
        Debug.Log(enemySpeed);
        yield return new WaitForSeconds(7);

        enemySpeed = enemySpeed * 2;
        Debug.Log(enemySpeed);
    }
}

OrbMovement 移动逻辑脚本

using Obscure.SDC;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class OrbMovement : MonoBehaviour
{
    Crosshair cs;
    Rigidbody rb;
    [SerializeField]private int orbSpeed = 40;
    [SerializeField] private Transform firePoint;
    // Start is called before the first frame update
    void Start()
    {
        rb= GetComponent<Rigidbody>();
        gameObject.GetComponent<Rigidbody>().useGravity = false;

        cs = GameObject.Find("Crosshair").GetComponent<Crosshair>();
        firePoint = GameObject.Find("OrbSpawnPos").GetComponent<Transform>();

        GetComponent<Rigidbody>().AddForce((cs.GetHitPoint() - firePoint.position).normalized * orbSpeed, ForceMode.Impulse);
    }
}

已尝试的排查措施

  • 检查第一人称角色/相机的碰撞器配置
  • 确认投射物和敌人都已添加Rigidbody与Box Collider组件
  • 调整过IsTrigger和IsKinematic的参数设置
  • 修改过项目设置中的层碰撞规则

相关配置截图

  • 碰撞层设置
  • 投射物预制体设置
  • 敌人预制体设置

内容的提问来源于stack exchange,提问作者Adam Qureshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 15:54:54