Forum

Get objects on collision

22 June 2019 08:43
Hi everyone,

I would like to know if there is a way to get the object_ID (or data_id) of two colliding objects? To be clear, please let me try to explain my problem. I have a scene with an object (a cube) that is moved with the mouse. Then, every 3 seconds an OBJECT is loaded dynamically in the scene (this is a model loaded from a .json file with animation and physics properties defined, including de collision_id). My goal is to touch the OBJECT with the cube and then the OBJECT have to be removed from the scene.
So my idea is to get the OBJECT_ID to later call m_scene.remove_object(OBJECT_ID) or something like that.

As many OBJECTS are loaded dynamically from the same .json file, all of them have the same collision_id, object_name in my scene, so I don't know how to distinguish which one have been touched with the cube.

I will appreciate any idea…

Thanks in advance
22 June 2019 08:45
Hi everyone,

I would like to know if there is a way to get the object_ID (or data_id) of two colliding objects? To be clear, please let me try to explain my problem. I have a scene with an object (a cube) that is moved with the mouse. Then, every 3 seconds an OBJECT is loaded dynamically in the scene (this is a model loaded from a .json file with animation and physics properties defined, including de collision_id). My goal is to touch the OBJECT with the cube and then the OBJECT have to be removed from the scene.
So my idea is to get the OBJECT_ID to later call m_scene.remove_object(OBJECT_ID) or something like that.

As many OBJECTS are loaded dynamically from the same .json file, all of them have the same collision_id, object_name in my scene, so I don't know how to distinguish which one have been touched with the cube.

I will appreciate any idea…

Thanks in advance
13 August 2019 13:57
Hi Walrus, I found your message recently.
I dynamically constructed a labyrinth. Each element (wall) was copied from a reference with new name.
The new object was then translated.

<The function>
// uses modules scenes, objects and transform.
var n = -1 //global

function DuplicateMX(x, y) {
var obj = m_scs.get_object_by_name("MX"); // reference object
var new_obj_name = "MX" + n++;
var new_obj = m_obj.copy(obj, new_obj_name, true); // new object(mesh) with new name (deep copy)
m_scs.append_object(new_obj);
m_trans.set_translation(new_obj, x-9, y-5, z); // new position
}
</The function>

The copy is a new mesh and should carry the same properties (except name).
It is required to enable the "Rendering Properties > Dynamic Geometry checkbox" for the source object in blend file.
Re-reading json is not necessary.

I hope it will be usefull.
 
Please register or log in to leave a reply.