Difficulties with ladders and vector math

Like the title states, I am having some serious trouble getting the vector math behind ladders to work exactly how I want it to. I’ll try to be as clear as possible since a video would make it far easier to explain :).

For walking I use the standard +z = forward, +y = up, +x = right as so:

desiredMove = Vector3.forward * inputVector.z + Vector3.right * inputVector.x + Vector3.up * inputVector.y;

Player movement axis:
2298720--154717--player axis.PNG

My desired functionality is that when I am on a ladder AD will only translate a player along the ladder’s x-axis, and WS will translate a player along the ladder’s y-axis. So in the following two images, I will only translate along the respective x(red) and y(green) axis for each ladder:
2298720--154719--upright axis.PNG 2298720--154718--diagonal axis.PNG

The best I’ve come up with is getting a quat to rotate my desired movement towards the up-axis of the ladder. What this didn’t do, however, is keep my sideways movement locked to the moving along the x-axis of the ladder. Any ideas of how I can get what I want?

If I assume a few things…

  1. code is on player
  2. player only moves left right on x-axis (player doesnt rotate)
  3. ladders are on 45* angles
speed = inputVector.x * moveSpeed;

transform.Translate(transform.forward  * speed + Vector3.up * speed);

Well yeah, that’s the trouble - I want the player to be able to look around while they’re on the ladder.

Why dont you just let the physics do it then…

Can’t. The whole thing is on a ship that can corkscrew through the level. And for other reasons I can’t have the ship stationary while the rest moves, or show it what’s happening via camera.

well that makes it complicated…

Can you clarify what you mean by ‘look around while on the ladder’. Will the player only ever walk left or right?

No, they can walk as a typical fps character controller. But they need to be able to continue to mouse-look while they’re going up and down on the ladder.

So you want the x-axis of the ladder’s transform to dictate the moving direction when they push left or right (AD), and the ladder’s y-axis dictates the moving direction when the player presses up or down (WS).

something like:

Transform ladderTransform = *a reference to the ladders transform*;
Vector2 input = new Vector2(*AD*, *WS*);
Vector3 desiredMove = ladderTransform.up * input.y + ladderTransform.right * input.x; //multiply by speed if needed

Finally got it. I had to manually map my input directions to the axis of the ladder object in world coordinates, then convert to my player’s local coordinates:

Vector3 ladderRight = ladder.transform.right * inputVector.x;
Vector3 ladderUp = ladder.transform.up * inputVector.z;
Vector3 ladderForward = ladder.transform.forward * inputVector.y;
desiredMove = ladderForward + ladderRight + ladderUp;
desiredMove = this.transform.InverseTransformVector(desiredMove);