How to move a mesh towards its Z axes?

I want to move my mesh for some distance towards its Z axes. How to do it?
I’m trying to make a solution around Math.atan2() function but I fail with it

https://doc.babylonjs.com/typedoc/classes/babylon.mesh#translate

mesh.translate(BABYLON.Axis.Z, 1337, BABYLON.Space.LOCAL);

3 Likes

@Rata_Blanca You had posted asking how to do this using the physics engine (I think) but I see the post is deleted now. In case you still have this question:

I haven’t used it myself, but if you need to get the position in world space after doing the translation in the local space of the mesh, you can do the math using a Vector that matches your mesh position and then by using the matrix of the object and world to translate and convert as needed.

You could also simulate the same thing by just using a temporary TransformNode with the same position and rotation as your mesh, then translate it, call getAbsolutePosition, and use the value it gives you back (which will be in world coordinates, if that’s what you need).

1 Like

Yeah, that’s too easy. If I need to use it with moveWithCollisions() I can just do following:

const direction = testObj1.getDirection( BABYLON.Axis.Z ).normalize();
testObj1.moveWithCollisions( direction * 2.0 );
1 Like