I built this first-person perspective 3D room with a dual VirtualJoystick (left to rotate and right to move) (https://playground.babylonjs.com/#R7KZRR#1). And it works fine in the player’s initial position, but as soon as you rotate the player, the movement is incorrect. Basically these lines make them rotate and move:
// Virtual Joystick UP DOWN LEFT RIGHT *** HELP HERE ***
if(joysticks.rightPuck.isDown){
player.nextspeed.x = v*0.01*joysticks.xAddPos;
player.nextspeed.z = -v*0.01*joysticks.yAddPos;
}
// Virtual Joystick movement rotation *** HELP HERE ***
if(joysticks.leftPuck.isDown){
player.rotate(BABYLON.Axis.Y, -joysticks.yAddRot*0.01, BABYLON.Space.WORLD);
}
If I take the vector J ( Joystick ) and the P ( Player ) to calculate the M ( Move ) is not a simple Addition of Vectors but is like to prolongate the coordinates axis J into the direction of P and then calculate the Addition of Vectors. ( See graph )
And I’m not sure how to calculate the correct formula and values to make this work on babylonjs.
Rotate and move also works well with keyboard keys. Arrows to move. The “Z” and “X” to rotate. I appreciate any help. Thank you!