Continuous collision detection for triggers?

says:

Do continuous and continuous dynamic collision detection work with trigger colliders?

No. Continuous helps prevent the rigidbody from passing through the collider it collided with. With a trigger, there is no ‘collision’ in the sense of having a physics reaction.

Is there some kind of work around? If the trigger is a box can it sweep from the position in the previous frame to the position in the current frame so that the entire volume works as a trigger? (it is a rotating box though)

Yes, use queries.

Yes, use queries.

I found this but I’m not sure if those queries apply to triggers:

https://docs.unity3d.com/Packages/com.unity.physics@1.3/manual/collision-queries.html

Also does it work with the other objects’ OnTriggerEnter?

I don’t use DOTS physics and I’m not on the team but it should be super quick to give it a try so have you tried? :wink:

I don’t understand the question. Contact callbacks are completely unrelated to queries.

It seems you’re both misunderstanding each other. When Melv says “Use Queries” I believe he means use Raycast or SphereCast, not entities physics.

To get around the discrete collision detection of triggers you could try using modifiable contacts which will allow you to move an object quickly that can pass through other objects but still detect collisions. So basically create your own version of a trigger.

@MelvMay Sorry I didn’t realize that link was DOTS. Maybe I could use BoxCast? Basically what I want to do is for it to act like a trigger.

Again, it would take seconds to just try. You can use any query you like. If you want to cast a box then yes, BoxCast is what you need.

If you take a moment to look at the docs you’ll see how to use it: Unity - Scripting API: Physics.BoxCast

In the first line on the page you’ll see Unity - Scripting API: QueryTriggerInteraction

1 Like

Thanks though I don’t think BoxCast can do what I’m after… I want the box to have a before and after rotation (and the BoxCast should sweep between them). Also it is the trigger that I’ve got moving around everywhere (it is a sword). I just decided to slow down the speed of the box trigger so that it doesn’t jump too far each frame.

@MelvMay

So I’m making the sword blade be a trigger (with a base blade position and an end position). The choppable objects use OnTriggerEnter and OnTriggerExit.

But if the blade moves too fast the objects don’t detect the chop.

So I was thinking, there could be a trigger involving a dynamically created triangle. The points are the previous blade’s tip position, the current blade’s tip position and the current blade’s base position.

Hopefully a dynamically updated triangle could be used as a trigger and activate OnTriggerEnter and OnTriggerExit. ???

It would be better if it could also have a 4th point - the previous blade’s base position - but it sometimes wouldn’t be possible for those 4 points to be a flat surface.

When this code is used with MeshCollider the Player falls down when the mesh moves from underneath them.

When I enable isTrigger, OnTriggerEnter on another mesh is called each time the trigger is updated and touching the mesh. OnTriggerExit is never called.

    private void MakeMeshData()
    {
        movingVerticesIndex = (movingVerticesIndex + 1) % 3;
        float vertexZvalue = (movingVerticesIndex * 2) + 1;
        vertices = new Vector3[] {
            new Vector3(0, 0, 0),
            new Vector3(0, 0, vertexZvalue),
            new Vector3(1, 0, 0),
            new Vector3(1, 0, vertexZvalue),
        };
        triangles = new int[]
        {
            0, 1, 2,
            2, 1, 3
        };
    }
    void CreateMesh()
    {
        mesh.Clear();
        mesh.vertices = vertices;
        mesh.triangles = triangles;
    }
    IEnumerator RegularlyUpdateMesh()
    {
        while (true)
        {
            MakeMeshData();
            CreateMesh();
            meshCollider.sharedMesh = mesh;
            yield return new WaitForSeconds(2f);
        }
    }