Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Raycast with standard Rigidbodies and Colliders

Discussion in 'Physics for ECS' started by Aethenosity, Jul 18, 2023.

  1. Aethenosity

    Aethenosity

    Joined:
    Jun 2, 2017
    Posts:
    15
    Do we still need the custom authoring physics samples (shapes and bodies) to handle CollisionWorld.CastRay and other casting functions?

    I thought I saw somewhere that standard RBs and Colliders work too, but I can't seem to get that working.

    Also, apologies if this has been asked before. I couldn't find a thread post 1.0.
     
  2. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    274
    The only thing that matters for CollisionWorld queries is that the appropriate Unity Physics baked representations of the colliders are present. Both custom authoring and classic Collider / Rigidbody components are baked to the same components (PhysicsCollider, PhysicsMass, PhysicsVelocity, ???) as long as they exist within a SubScene that gets baked. You should see the corresponding baked physics components for that object in the Entities Hierarchy view regardless of how the collider and rigidbody were authored.
     
    Aethenosity likes this.
  3. Aethenosity

    Aethenosity

    Joined:
    Jun 2, 2017
    Posts:
    15
    Alright, I see that you're right and I didn't look closely enough. I see the Physics Collider, Physics Gravity Factor, Physics Mass, and Physics Velocity.

    My issue was trying to raycast for my units and I don't know how to set the Collision Layer for the unit to use in my CollisionFilter.

    With the Custom Authoring it looks like you can simply set these layers. These layers are different from the normal layers in Unity, right?
     
  4. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    274
    They are related but decidedly distinct. The concept of "normal layers" does not really have a presence within a World outside the subsystem-specific representation of layers. "Normal layers" can bake to Unity Physics layermask values and the render layer for Entities Graphics RenderFilterSettings.

    Additional information that may be pertinent:

    The "normal layers" (the layer a GameObject is set to belong to) are used to generate the appropriate values in Unity Physics as well as Entities Graphics. When converting a Collider, the BelongsTo mask will be the object layer, and the project's collision matrix (Edit/Project Settings/Physics/Layer Collision Matrix) is used to set the CollidesWith value based on the object layer.

    The Collider component now has the includeLayers and excludeLayers fields, which logically should be used as another part of producing the CollidesWith value, but currently, this is not the case. This may be a bug, one that Unity has previously been made aware of.

    For now, the best solution for cases requiring overrides for specific objects seems to be using the custom authoring. There's a gap in functionality between what they want you to use (Collider, Rigidbody, etc.) and the authoring components that were created specifically for Unity Physics. Ideally, only the classic components would be needed, but they're not there yet.
     
    Aethenosity likes this.
  5. Aethenosity

    Aethenosity

    Joined:
    Jun 2, 2017
    Posts:
    15
    Thank you so much. That was very clear and helpful!