Jump to content

mesh.parent seems to mess up vectors of children


georage
 Share

Recommended Posts

http://www.babylonjs-playground.com/#3HNIJ#1

I am trying to create a Fischer Price type toy with three meshes. I was thinking I could combine the three meshes and have one solid mesh and just move one mesh. Originally I tried connecting them with joints to give the character parts a little movement but the joints were way too loose.

After creating and positioning my three meshes, whenever I try to make one mesh a parent it changes the location of the children. That seems very weird. 

Any ideas on how to combine these meshes? I tried another method (forget what it was called) and it said it was deprecated and to use child/parent.

I want the option of making the meshes different colors too.

Thanks for any tips.

 

 

Link to comment
Share on other sites

Thanks, I figured it out. 

The trick is to make the lowest mesh the parent. Or at least that worked for me. I will try your method.

It is very strange that children inherit the x and z values of the parent, but not the y value. It seems the values would be absolutes until the render loop runs.

http://www.babylonjs-playground.com/#3HNIJ#4

 

EDIT: I tried JohnK's suggestion (setting the parent after creating the meshes but before positioning them and it did not work. The playground linked above is the only way I could get it to work.

 

Edited by georage
I tested JohnK suggested
Link to comment
Share on other sites

Very cool Wingnut, thanks. Very helpful.

I think part of my problem was trying to create the meshes at a non-zero spot ... i was creating the hockey players in their positions instead of at center ice. Changing the x and z positions of the meshes before parenting was rocking my brain!

Link to comment
Share on other sites

Thanks to everyone's help I have this working reasonably well, but only the parent mesh seems to have collisions? 

Right now when the toy players fall over only their feet collide with other player feet. I would like the body and head to also give collisions.

I tried adding impostors to the children in the makePlayer function but things got really weird ... the players started flying apart like the parts were exploding! 

 

Link to comment
Share on other sites

Did someone call me?

Physics? Yei! Parenting? YEAH! 

So, this is how it is done - http://www.babylonjs-playground.com/#3HNIJ#14

You set impostors to all of the child meshes, and then set an impostor to the parent. The parent then "removes" the other impostors and creates a single compound. Now the body1 impostor controls all three together.

Click your mouse and see what happens when you apply impulse to the body. I noticed a small bug (which was not intended) regarding the physics impostors of the others (which are simply removed and not available), but that shouldn't stop you from developing your great game.

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...