valepu Posted June 26, 2016 Share Posted June 26, 2016 I've tried searching google on this but i can't seem to find a solution. What i want to achieve is that if i set a rotated mesh as parent then translating it through an axis would move it in the same direction as if it didn't have a rotated parent. For example in this playground http://www.babylonjs-playground.com/#26DEBS#0 I would like the sphere to go "up" rather than towards the camera. Quote Link to comment Share on other sites More sharing options...
adam Posted June 26, 2016 Share Posted June 26, 2016 I would add an empty mesh in between the ground and the sphere and rotate it to negate the rotation of the ground. http://www.babylonjs-playground.com/#26DEBS#2 Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 27, 2016 Share Posted June 27, 2016 I don't understand your question. Could you explain actual usage? Cheers, DB Quote Link to comment Share on other sites More sharing options...
valepu Posted June 27, 2016 Author Share Posted June 27, 2016 8 minutes ago, dbawel said: I don't understand your question. Could you explain actual usage? Cheers, DB I create a mesh A, rotate it by 90° on the X axis I create a mesh B and set A.parent = B i translate B on the y axis, but it doesn't move on the global y axis ("up"), it moves on the parent's rotated axis The additional mesh could work but i was wondering if there's a more "conventional" solution (like a special rotation function that uses world axis) Quote Link to comment Share on other sites More sharing options...
JohnK Posted June 27, 2016 Share Posted June 27, 2016 The idea of a parent is that the child moves relative to the parent. This page from the documentation describes some of the relationship between parent and child and positions and rotation. http://doc.babylonjs.com/tutorials/Position,_Rotation,_Scaling This page from the documentation does not deal with parenting but does show rotation and translation using the world axis http://doc.babylonjs.com/tutorials/Position,_Rotate,_Translate_and_Spaces If you are simply doing a rotation of -PI/2 as in your PG then you know that the z axis of the ground in now screen up as in http://www.babylonjs-playground.com/#26DEBS#8 If you want something more complicated then please try to describe the situation you are aiming for, it might all come down to when you set the parent. Quote Link to comment Share on other sites More sharing options...
valepu Posted June 27, 2016 Author Share Posted June 27, 2016 I know the theory behind and i know i could just translate it over the right axis. My problem lies on the fact that i might have a function that should be "mesh agnostic" and does a translation over an axis. Say: function goUp(mesh) { mesh.position.y += 1; } if i pass to this function a mesh with a rotated parent (any kind of rotation) it won't move the mesh "up" Mind that this is just an example (and i don't have a more concrete one) so using another approach is not the solution here Quote Link to comment Share on other sites More sharing options...
adam Posted June 27, 2016 Share Posted June 27, 2016 What's wrong with my answer? Quote Link to comment Share on other sites More sharing options...
valepu Posted June 27, 2016 Author Share Posted June 27, 2016 2 minutes ago, adam said: What's wrong with my answer? Nothing, i'd just like to know if there's (or if it can be implemented) a "native" method to do that Quote Link to comment Share on other sites More sharing options...
adam Posted June 27, 2016 Share Posted June 27, 2016 Another possible solution is rotating the vertices of the parent instead of rotating the coordinate system. Edit: performance is much worse with this solution though. If you are going to be rotating the parent every frame, I would go with the extra mesh solution. valepu 1 Quote Link to comment Share on other sites More sharing options...
adam Posted June 27, 2016 Share Posted June 27, 2016 http://www.babylonjs-playground.com/#26DEBS#9 valepu 1 Quote Link to comment Share on other sites More sharing options...
valepu Posted June 27, 2016 Author Share Posted June 27, 2016 Thanks, i guess that's the closest one can get to a "native" function Quote Link to comment Share on other sites More sharing options...
adam Posted June 27, 2016 Share Posted June 27, 2016 Looks like there actually might be a more conventional solution. Look at changing the frame of reference at the bottom of this page. https://doc.babylonjs.com/overviews/How_Rotations_and_Translations_Work Edit: I didn't have any luck getting a playground working using TransformCoordinates. Maybe someone else will. valepu 1 Quote Link to comment Share on other sites More sharing options...
dbawel Posted June 27, 2016 Share Posted June 27, 2016 There are many good solutions that would work, however now that I understand what you want to do, simply parent both mesh A and B to a null or transperent object. Then rotate mesh A and translate mesh B all you want. And if both must translate together, then translate the parent object. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.