jangbi Posted May 20, 2018 Share Posted May 20, 2018 Here's the demo. https://www.babylonjs-playground.com/#LS4I1S Firstly, I want to move the cylinder forward(in local axes), so i use mesh.translate(BABYLON.Vector3.Forward(), 1). The cylinder move 1 unit in the y axis instead of z axis(that's what i want), I can understand why the cylinder move in the y axis(because of the rotation), but I want to know how to move the cylinder on the x-z plane forward after rotation by using the local frame of reference. Secondly, how to compute the segments' two end points dynamically, is my code right? this.mesh.computeWorldMatrix(); let matrix = this.mesh.getWorldMatrix(true); this.vertex1 = BABYLON.Vector3.TransformCoordinates(this.vertex1, matrix); this.vertex2 = BABYLON.Vector3.TransformCoordinates(this.vertex2, matrix); (My english is poor, please forgive me) Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 20, 2018 Share Posted May 20, 2018 Does this help you? https://doc.babylonjs.com/features/position,_rotation,_scaling#move-by-methods Quote Link to comment Share on other sites More sharing options...
jangbi Posted May 21, 2018 Author Share Posted May 21, 2018 @JohnK I've already read that page. Be more specifically, in this demo, i want to move the cylinder's location to (0,0,1), but not using the position.z += 1, use the local frame of reference and a local orientation vector to finish the translation.And calculate the correct segment's vertex position while need it. Quote Link to comment Share on other sites More sharing options...
JohnK Posted May 22, 2018 Share Posted May 22, 2018 It seems to me that you want to move in world space not local space https://www.babylonjs-playground.com/#LS4I1S#1 or if you want to use local axes then you need to move in the y direction https://www.babylonjs-playground.com/#LS4I1S#2 NOTE - BABYLON.Vector3.Forward() = BABYLON.Axis.Z = (0, 0, 1) This might be worth a read as well 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.