In the VR Kit template the movement for VR is either teleport or by using the controllers on a flat plane. My environment however requires the player to be able to move up and down slopes and stairs etc and so my original PC version using mouse and keyboard used rigibody and applyforce to do this.
I have tried altering the VR camera-controller code to make it use rigidbody instead but the player entity moves very little and there are some side effects with the vr camera rotating strangly.
If anyone has any solutions to this I would be keen to hear. Many Thanks.
Here is my code:
CameraController.prototype.onMove = function(x, y, dt) {
this.vec2A.set(x, y);
if (this.vec2A.length()) {
this.vec2A.normalize();
this.vec2B.x = this.camera.forward.x;
this.vec2B.y = this.camera.forward.z;
this.vec2B.normalize();
var rad = Math.atan2(this.vec2B.x, this.vec2B.y) - (Math.PI / 2);
var t = this.vec2A.x * Math.sin(rad) - this.vec2A.y * Math.cos(rad);
this.vec2A.y = this.vec2A.y * Math.sin(rad) + this.vec2A.x * Math.cos(rad);
this.vec2A.x = t;
this.vec2A.scale(this.movementSpeed);
//this line is the old one which moved the player on a flat p/ane
//this.entity.translate(this.vec2A.x * dt, 0, this.vec2A.y * dt);
//new code uses forces and rigidbody
let x_mov= this.vec2A.x * dt;
let z_mov= this.vec2A.y * dt;
if (x_mov !== 0 || z_mov !== 0) {
this.force.set(x_mov, 0, z_mov).normalize().scale(this.movementSpeed);
this.entity.rigidbody.applyForce(this.force);
}
}
};