Forum

Object collision not working

13 July 2016 17:31 #10453
Hello,

my name is Fabio and I am really new here :-)

In a test project I am writing, I am trying to detect cubes collisions but there must be something that escapes me because the events are not fired.

My code is quite simple: for each cube in my scene, I do the following:

var obj = objs[i];

                if ( m_phy.has_physics(obj) )
                {
                        m_phy.enable_simulation ( obj );

                        // create sensors to detect collisions
                        var sensor_col = m_ctl.create_collision_sensor ( obj, "ANY" );
         
                        m_ctl.create_sensor_manifold (
                                obj, "COLLISION", m_ctl.CT_CONTINUOUS, [ sensor_col ],
                                function ( o ) { return o [ 0 ]; }, function ()  { console.debug ( "HIT!"); }
                        ); 
                }


but even if the objects actually collide in the scene, the "HIT!" message never appears on my debug console.

What should I check?

Thank you for the support.

Ciao
Fabio
http://www.os3.it
13 July 2016 18:04 #10456
Hello and welcome to the forum.

Take a look at this article please. I hope, it'll be helpful. Also, you can find the demo in the SDK (SDK/deploy/tutorials/examples/cartoon_interior/)
Blend4Web developer
13 July 2016 18:18 #10457
Hi Roman,

thank you very much.
I've already looked the article you say and had a look to all the SDK examples.
I think my objects / material are ok in Blender.
I spent all the afternoon searching for my mistake, with no hope .. :-(

Ciao
Fabio
http://www.os3.it
13 July 2016 18:44 #10459
Could you send me your project (or simple example with strange behavior)? You can attach it to message. Project Manager can export projects.
Blend4Web developer
14 July 2016 09:40 #10461
Or show me please your main .js file
Blend4Web developer
14 July 2016 09:48 #10462
Hi Roman,

thank you for your help. I have attached my basic project to this message.

I am pretty sure it is something very simple, but I am missing it

Ciao
Fabio
http://www.os3.it
14 July 2016 14:48 #10471
Hello.

Here is your corrected .js file:
function load_cb(data_id, success) 
{
	if (!success) {
		console.log("b4w load failure");
		return;
	}

	m_app.enable_camera_controls();

	var mirino = m_scenes.get_object_by_name ( "Circle" );

    	var from = new Float32Array(3);
    	var to = new Float32Array(3);

	var s1 = m_ctl.create_collision_sensor ( mirino, "cubo" );
	var s2 = m_ctl.create_collision_sensor ( mirino, "cubo02" );

	m_ctl.create_sensor_manifold ( 
        mirino, "IMPACT", m_ctl.CT_CONTINUOUS, [ s1, s2 ],
        function ( sensor_values ) {
            return sensor_values [ 0 ] || sensor_values [ 1 ]; 
        },
        function (obj, id, pulse)  {
            if (pulse == 1)
                document.getElementById ( "dbg" ).innerHTML = "CONTACT";
            else
                document.getElementById ( "dbg" ).innerHTML = "";
        }
    );
}


Also I've enabled the "ghost" object physics property and append the Collision ID (cubo and cubo02)
Blend4Web developer
14 July 2016 16:24 #10479
Hi Roman,

now it works perfectly. Thank you very much for your support and fast reply :-)
http://www.os3.it
 
Please register or log in to leave a reply.