Forum

Collision Detection (SOLVED)

25 October 2016 19:37
Hello All!

Is there a link to more details on collisions sensors and how they should be used, how they work somewhere? There are many scenarios for how this feature could be used and very short on docs. When to use materials with special collision properties, when to use Physics Collision ID, when and why to use collision bounds or not, how should the margin be set on collision bounds and why.. so many questions..

My particular situation is, I'm trying to reset some variables when a character collides with the ground.. but like the attached and example from manual, I can't get the sensor to fire on collision.

here are some more details, any help would be much appreciated!!
I'm trying to figure out how collision detection works. I'm using the example from APP developer section of API. https://www.blend4web.com/doc/en/developers.html#event-driven-model

Attached a simple project to test out the example in documentation.. doesn't work?

I found a type-o in the documentation .. m_ctl in the following line should be m_controls.
// create the manifold
m_controls.create_sensor_manifold(stone, "IMPACT", m_ctl.CT_SHOT,
impact_sens_array, impact_sens_logic, impact_cb);
25 October 2016 21:09
I'm looking at this article trying to see if I can sort out the manual example
https://www.blend4web.com/en/community/article/66/
I've tried some variations of the settings in this article to try and get manual example working, so far no luck.

I can't find anything that explains what this function does?
m_phy.enable_simulation(obj);
26 October 2016 00:20
So after more testing It doesn't appear that the Material Special Collision Works No matter what I try? How does this work, what settings should be enabled and how, does anyone have an example of how you would use multiple materials as well as how the collision layers work?


In case someone else is looking for just a basic working collision example the code below works with the attached collisionTest.blend file
The only thing you need to get basic collision working is a Collision ID in the Physics panel.
No Actor, No Ghost, No Collision Bounds. I set the controls to CT_TRIGGER so the collision would fire every time it makes contact. I wouldn't mind seeing some kind of examples for each case, the purpose for actor, ghost collision bounds if someone knows how they work and when you use them.

// get the object being thrown
var stone = m_scenes.get_object_by_name("Stone");

// create the sensors
var sensor_impact_terrain = m_controls.create_collision_sensor(stone, "TERRAIN");
var sensor_impact_wall    = m_controls.create_collision_sensor(stone, "WALL");

// array of the sensors
var impact_sens_array = [sensor_impact_terrain, sensor_impact_wall];

// manifold logic function
var impact_sens_logic = function(s) {return (s[0] || s[1]);}

// callback
var impact_cb = function(obj, manifold_id, pulse) {

    // NOTE: it's possible to play both sounds simultaneously

    if (m_controls.get_sensor_value(obj, manifold_id, 0) == 1) {
        // ...
        console.log("play the terrain impact sound");
    }

    if (m_controls.get_sensor_value(obj, manifold_id, 1) == 1) {
        // ...
        console.log("play the wall impact sound");
    }
}

// create the manifold
m_controls.create_sensor_manifold(stone, "IMPACT", m_controls.CT_TRIGGER,
    impact_sens_array, impact_sens_logic, impact_cb);

}
26 October 2016 02:53
If I enable the 'Stone' object in Blender as a character the collision sensor stops working?
02 November 2016 21:06
The solution I found.. add a simple cube. add a material.
In the physics panel leave collision ID: <blank>
In physics panel check the 'ghost' box
In the material panel at the bottom select 'special collision' and again check 'ghost'
in the material panel under 'special collision' using the example above enter in 'FLOOR' in the Collision ID.
If you want to hide the object that is being collided with go to 'object' panel and check the 'do not render' checkbox under render settings.

So interestingly, the collision object still interacts with the character object, even if it's invisible you can still stand on it as ghost.

Also, I found that changing the dimensions of the cube (even with CTRL S, Apply Scale) cause the interaction with the collision to be a little finicky.
On the Blend4Web tab on the toolshelf (hotkey t) there is an option to manually set the collision bounds of the object. Some adjustment to my character capsule and the object with the special collision material helped to get it working consistently.
 
Please register or log in to leave a reply.