Jump to content

setContactCallback


photo

Recommended Posts

Hi.

 

Trying to do this:

void contact_callback(){
 log.message("callback.");
}
// ...
bodyRigid.setContactCallback("contact_callback");
// ...

 

But, I get this:

post-36-0-60434400-1297983731_thumb.png

 

Removing that setContactCallback line gets rid of the error.

Link to comment

We can't reproduce the problem.

 

samples/physics/callbacks_02 sample works normally without callback arguments.

 

Yes, it works normally when I use it in a World loaded by the provided main_x64.exe, for example.

 

But when loading the world with that script in my custom application, the error occurs.

 

Since you are able to access the source code, could you take a look at the source of the assertion to see what might cause the error message?

 

Everything else has worked fine in the my custom application, so not sure why setting a contact callback would fail only for my application, and not in the provided applications.

Link to comment

A question regarding how contacts work.

 

Do contacts only occur if two shapes collide as a result of a physics update?

As in, gravity causes one shape to hit another, contact occurs.

But if I call setTransform, such that the shapes collide, no contact occurs?

 

If this is the case, how can I detect collisions as a result of a setTransform movement?

Link to comment
  • 3 weeks later...

Basically, physics is updated each tick in the following way:

 

  1. All physics functions called manually from the world script are executed. This means, new body transformations are set, callbacks for collisions (if there will be any) are registered etc.
  2. Physics is simulated. That is, collisions between the bodies are calculated, joints are solved (with specified number of iterations), callbacks are triggered.
  3. Flush. This is when rendered objects are synchronized with their physical bodies: if there is a change in position, object coordinates are updated.

Link to comment

Hi Manguste,

 

Thank you for the response. I have been waiting some time for this.

 

To clarify:

Step 1: world script update() : user control

Step 2: physics simulation

Step 3: worldscript flush() : user reacts to updated physics

 

I would like to use a BodyRigid to simulate a sword which is attached to the corresponding mesh.

I should, instead of setting the transform of the mesh (which is the default in the Character system for attachments),

I need to set the transform of the Body during step 1!

 

This allows the physics to react to the body's collision, which should be physically resolved (moved out of collision) prior to Step 3?

Allowing me to react to the solved physics state in Step 3, the flush? For example, setting up my IK to reach the physically solved position/orientation.

 

 

Thanks for this explanation, I will give this approach a shot. Though, the setContactCallback crash may still occur. I'll let you know how it goes.

Please let me know if my reasoning above is correct.

Link to comment

Hope you got your questions answered :) To sum it up about callbacks:

1. You can set callbacks anywhere: within init(), update() or flush().

2. When physics is simulated, callbacks are triggered by contacts, but it only means they are placed in a queue.

3. Callbacks are actually executed first thing next frame or (if there are some more physics iterations following) in the next iteration before physics is simulated one more time.

Link to comment
  • 2 months later...

The issue disappeared when we created small test cases for the ragdoll. However, now that I am integrating the code into my main application framework, the problem arises again.

 

Basically, if you call setContactCallback() in a method that is called from C++ interface. Crash occurs. Attached is the error message.

 

Unigine::Engine::get()->runWorld("testRagdoll");

 

This line will cause the attached error message.

I’m guessing this has something to do with setting a callback, which causes the engine to search for the function by exploring the call stack.

 

However, calling from C++ causes that search to end prematurely. I hope you can include the fix for this in the next release.

Link to comment

Unigine::Engine::get()->runWorld("testRagdoll");

 

Just to be sure, this c++ call is properly wrapped by Unigine::Engine::get()->pushWorld()/popWorld() calls, right ?

Link to comment

Just to be sure, this c++ call is properly wrapped by Unigine::Engine::get()->pushWorld()/popWorld() calls, right ?

 

Actually, I did not. As my understanding of push/pop was that it is to be used when passing extern class variables to and from script. Whereas as simple function call does not require it.

However, I can see how push/popping world context might be required in namespace resolution. I will give this a try.

 

Good idea, Ulf!

Link to comment
×
×
  • Create New...