Jump to content

Rotate Mesh but keep child axis orientation


valepu
 Share

Recommended Posts

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.

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

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