Hey all, I can’t seem to resolve this, no matter how I approach it, and my google-fu isn’t turning up much info.
I have a player controller that’s working pretty well, but I’m having trouble with climbing, or more specifically, getting the player to align itself correctly with the various faces on a cube.
The function below is as close as I’ve gotten. The player will align correctly with only one face of the cube. It does this nicely, and sticks to the correct plane. It will only do this for the one face though.
function climbingOrientation(ray, player) {
const hit = scene.pickWithRay(ray);
if (hit.hit) {
const surfaceNormal = hit.pickedPoint;
console.log(surfaceNormal);
if (surfaceNormal) {
player.up = surfaceNormal;
player.right = surfaceNormal;
const targetQuaternion = BABYLON.Quaternion.RotationQuaternionFromAxis(
BABYLON.Vector3.Right(),
surfaceNormal,
BABYLON.Vector3.Forward()
);
BABYLON.Quaternion.SlerpToRef(
player.rotationQuaternion,
targetQuaternion,
0.1, // Smoothing factor
player.rotationQuaternion
);
}
}
}
I’ve recreated my issue on the following playground:
Wall Climbing - Playground (updated)
I would love any help. I’ve been banging my head into the wall on this, but I can’t really proceed on other tasks with this one currently DOA.
When testing, the face labelled 1 is working correctly. You have to hold the forward button down for a second or two at the top of the climb to get the player to the top of the box.
The function in question is on line 68
WASD, Space for controls.
Thanks in advance!