I tried to make an example for collision checking of 2 prims in a behavior script. Unfortunately doesn’t give the expected result. It worked for or 2 times when I tried it in the debugger, but refused to call the “on_contact_report_ActCollision”
Here is my code:
from omni.kit.scripting import BehaviorScript
from pxr import PhysicsSchemaTools, PhysxSchema, UsdPhysics
from omni.physx import get_physx_simulation_interface
import math
import time
class Actcollision(BehaviorScript):
def on_init(self):
print(f"{class.name}.on_init()->{self.prim_path}")
def on_destroy(self):
print(f"{__class__.__name__}.on_destroy()->{self.prim_path}")
def on_play(self):
print(f"{__class__.__name__}.on_play()->{self.prim_path}")
my_prim = self.stage.GetPrimAtPath('/World/Cube')
contactReportAPI = PhysxSchema.PhysxContactReportAPI.Apply(my_prim)
contact_report_sub = get_physx_simulation_interface().subscribe_contact_report_events(self.on_contact_report_ActCollision)
contactReportAPI.CreateThresholdAttr().Set(1)
def on_contact_report_ActCollision(self, contact_headers, contact_data):
for contact_header in contact_headers:
# instigator
act0_path = str(PhysicsSchemaTools.intToSdfPath(contact_header.actor0))
# recipient
act1_path = str(PhysicsSchemaTools.intToSdfPath(contact_header.actor1))
if act0_path.find("Station") or act0_path.find("Cube"):
print(act0_path)