I need some help again…
I saw some topics RE my problem and implement approaches that I saw there:
But unfortunatelly this approaches doesnt work for me because I want to prevent changing of moving direction.
Problem
So when I move mesh by +Y/-Y +X/-X +Z/-Z surfaces
And when mesh moves from Z surface to Y everything works fine as well as from X to Z etc. But when I move mesh from X to Y I have a strange behaviour that you can see in the video…
PG (Use arrows to move the mesh by surface):
Illustration
And I also prepare video that illustrate the problem:
Then I think your approach is not right, since your are defining the orientation of your box globaly, starting from the picked (ray) point, and the normal of the surface :
box.position = pick.pickedPoint!;
let normal = pick.getNormal() as BABYLON.Vector3;
let quaternion = BABYLON.Quaternion.Identity();
BABYLON.Quaternion.FromUnitVectorsToRef(
new BABYLON.Vector3(0,0,1),
normal,
quaternion
);
box.rotationQuaternion = quaternion;
While you should take into consideration, your speed (delta move from previous position)
Let me explain better.
As far as I understood you are happy with this :
But you are unhappy with this :
So what you are looking for (if I understood right) is, when going from X plane to Z plane, you want this :
But that’s inconsistent with the working version (first GIF). Have a look when going from Z plane to Y plane, to axis would not be in the same direction (orange points references) :
Sure ! What I was pointing, is that in the image both axis (on both orange points) have the same normal, while not the same orientation. So they cannot be set by a function which takes only the normal as reference. You must add a new var, such as the move direction…
@Tricotou
I updated the PG and as I understand I took in account direction of my mesh, using “forward”. But I still have this inverting of the axis when I go from +z to +y
I had a look in your code, I think the problem comes from the new logic you are trying to apply (merging the previous “moving with keyboard forward, backward, left, right” and the new “orientation depending on the move direction”)
I tried to draw the “loop” in a picture. Let’s say forward (up arrow) is toward X>0. No problem.
But now backward is toward X<0