Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved When RigidBody On, Raycast don't work!

Discussion in 'Physics' started by duan992014511, Nov 18, 2023.

  1. duan992014511

    duan992014511

    Joined:
    Nov 18, 2023
    Posts:
    2
    当我将 Rigidbody 组件添加到 Gameobject 时,此代码将不会进入。而当我删除 Rigidbody 组件时,此代码将正常工作。
    虽然我找到了Rigidbody的原因,但我想知道这样做的理由,谢谢。

    我用来获取游戏对象的代码:
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out hitInfo)) …
     

    Attached Files:

  2. duan992014511

    duan992014511

    Joined:
    Nov 18, 2023
    Posts:
    2
    hey… why I'm posted become to chinese?
    anyway, It looks like work just fine when I'm turn the Rigidbody's IsKinematic ON
    not sure exactly why, but it appears to be resolved.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,161
    The body type won't change how raycast or any physics queries work; they detect colliders not rigidbodies. It'll be some other logic in your scripts or you moving it somehow and it not actually being where you think it is.

    The forums don't do this so it's whatever you posted. It'll also cause it to go to moderation btw.
     
    duan992014511 likes this.