Hello. I am unsure how to realign the x, y, and z axes after rotating my character/model.
I added the camera as a child of the model (after async loading the model) to get the camera to stay with the model when rotating:
this.model.add(this.cam);
And then when I want to rotate the model with arrow keys, I do something like this:
moveWalker() {
let speed;
if (this.pressedShift) {
speed = 0.1;
} else {
speed = 0.02;
}
if (this.pressedLeft) {
this.model.position.x += -(speed);
this.model.rotation.y += 0.05;
} else if (this.pressedRight) {
this.model.position.x += speed;
this.model.rotation.y -= 0.05;
} else if (this.pressedUp) {
this.model.position.z += -(speed);
} else if (this.pressedDown) {
this.model.position.z += speed;
}
}
But now I am unsure how to realign what the “true z” is after rotating. So for example if I rotate the model around and press the “up” key, it continues to walk in the old “up” direction. I have attached a screencast to help explain what is happening.
I am actually wondering if adding the model as a child node of the camera was a mistake. But maybe there is a way to set the new axes after rotation by getting the direction of the camera?
Any advice would be greatly appreciated! Thank you.