Jump to content

Moving parent along with child


pepelito
 Share

Recommended Posts

Hello guys,

I have a little problem in my scenario. I am able to set the parent child relation among two meshes and i am able to move them along only if the parent mesh is dragged but not counter-wise. Both objects need to be able to be dragged and moved along together no matter which object is dragged. So i will be very thankful if anybody could help me.

 

Thanks!

 

Link to comment
Share on other sites

Hello,

I tried this logic manually setting the position to the parent. It is okay but i dont know why the child is moving faster than parent... If you have any idea i would be very thankful :)

Here is the code that i am using for setting parent position:

currentMesh.parent.position.addInPlace(diff);

where the diff variable is the change of position of the child mesh.

Here is the result: 

http://buragev.website/Cannon/index2.html

On image below:

P - parent

C - child

d0811dc0545f49f49436255930bccbc6.png

Link to comment
Share on other sites

Hello, 

I solved my problem and here is the PG for that: https://www.babylonjs-playground.com/#11PS7J#1. The main logic that was applied can be seen on line 92. If the picked mesh has a parent, then drag the parent, instead. The problem before was that when the child is dragged than the parent is dragging the child once again and that's why the child was moving more than his parent.

I must give almost all the credits to @Wingnut because he helped me a lot with my issue :) 

Cheers to @Wingnut and thanks to everyone. Hope that we will hang around more here! I will post my final game that i am working on when i will finish it, so i hope that you can see the final product soon. 

Cheers. 

Link to comment
Share on other sites

Yeah, we did a little behind-the-scenes talking, didn't we?  I like you, pep.  I hope we get to talk more.

I didn't do much work on issue solve.  I just borrowed Deltakosh's drag'n'drop demo... and did a little experimenting.  Pep was able to make it work for his project... so... YAY!  We scored yet another BJS victory.

Pep's end-user is a pretty important institute, so BJS will be shining bright in a place with plenty of eyes.  :)  It's all good.  Tell us all about the project, if/when you can, Pepelito.  Good luck, visit often.

Link to comment
Share on other sites

I like you too WIngnut, without you this wouldn't be solved probably :) The project is for National museum of Slovenia, so the visitors could play this game. I share the same thoughts that BJS will shine bright in a place with plenty of eyes !

Good luck to you too.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...