How to enhance the collision detector

When I start the simulation the collision detector is not always valid. Firstly, I set Simulation timeMode to VirtualTime, and set speedFactor to 4. Then I start the simulation asynchronously, the collision detector is a bit ineffective.
The start code:

Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Send, new System.Action(StartSimulation));

The simulation settings:

        public void TestFun()
        {
            //simulationFlag = 1;
            ISimulation simulation = _application.Simulation;
            simulation.TimeMode = SimulationTimeMode.VirtualTime;
            resetSimulation();
            simulation.RunTime = 100;
            simulation.SpeedFactor = 1;
            simulation.WarmupTime = 0;
            simulation.SaveState();
            simulation.Run(100);

        }

What exactly do you mean with “the collision detector is not always valid”? Are you getting VisualComponents.Create3D.InvalidWrapperExceptions?
If that happens then the underlying object has been deleted and your code can’t use it anymore.

No, I think the problem is from the SpeedFactor. I take a test that the bigger I set the SpeedFactor, the less accurate detector is. For Example, when I set SpeedFactor to 10 and launch simulation, it is no problem. But I set SpeedFactor to 0.04, everything else remains the same, and restart simulation. It shows that the collision happened.

The collision detection is by default done only when the world is rendered.

You can use IApplication.TestAllCollisionDetectors() to force a test to occur.
If you want to run some logic at specific times of simulation time (such as regular interval), use ISimulation.ScheduleCallback(...) method.

1 Like

Are there some differences between detector.TestAllCollisions() and IApplication.TestAllCollisionDetectors()

Don’t know, maybe the IApplication one skips disabled detectors or something.