Position a group of Objects relative to a specific side of another Object

Hi everyone,

I am trying to combine two walls at a specific position with respect to the first wall. But I am really stuck.
Below is the overview of what I am trying to achieve

These are the two models of walls rendered

Then I do Collision detection

Then I add it to a group. But they overlay on top of each other.

Below is what i am trying to achieve

Can some one please guide me on how to achieve it?

Pseudo code:

If Collision detected then
group them at a specific position (this is where I am really stuck at) :face_with_head_bandage:

I have tried setting the position of the Orange wall to White wall’s Frame’s position. But it didn’t work. It just translates along when the collision is detected.

Both the models are group of Meshes with buffer geometry type.

I’ll be highly grateful if someone can help me here. :slight_smile:

Thanks

I would do it like so: At the beginning, you have two meshes in your scene graph. When you detect a collision/intersection, you add one mesh as a child to the other one. By defining a relative transformation for the child mesh, you can keep a fixed position/rotation to the parent mesh even when the parent is transformed. Some pseudo code:

// assuming a collision between both meshes

frame.add( wall );
wall.rotation.y = Math.PI * = 0.5;
wall.position.x = 5;

// now you can transform "frame" and "wall" will keep its relative transformation to "frame"
1 Like

Thank you @Mugen87 for the help.

I implemented as you suggested and apart from little tweaks here and there it works like a charm. :slight_smile:

1 Like