“跟随功能”使我可以爬上梯子,向下爬梯子,而在梯子上什么也不做。
我在从梯子上跳跃时遇到麻烦。
我在X移动方向上被传送,然后掉到地上。
x =玩家和
-=跳跃行为
|-| =梯子
1。)|-| x
2。)|-| ------x(仅一帧)
那之后,我通常会像跳一样掉下来。
//PlayerController
//Ladder gets called in Update
private void Ladder(
{
//Jumping from Ladder
if (Input.GetKeyDown(KeyCode.Space))
if(!controller.isGrounded)
if (LadderClimb.canClimb)
{
Debug.Log("intend jump");
motion = true;
moveDirection.x = 0f;
moveDirection.x = (-jumpForce * 10);
moveDirection.y = -jumpForce;
}
//Pressing W on ladder
if (Input.GetKey(KeyCode.W))
{
if (LadderClimb.canClimb && !reverseClimbing) //Go Up
{
motion = true;
moveDirection.y = 0f;
moveDirection.y = (jumpForce * climbMultiplier);
if (!controller.isGrounded) moveDirection.x = 0f;
}
else if (LadderClimb.canClimb && reverseClimbing) //Go Down
{
motion = true;
moveDirection.y = 0f;
moveDirection.y = (-jumpForce * climbMultiplier);
if (!controller.isGrounded) moveDirection.x = 0f;
}
}
//Pressing S on ladder
else if (Input.GetKey(KeyCode.S))
{
if (LadderClimb.canClimb && reverseClimbing) //Go Up
{
motion = true;
moveDirection.y = 0f;
moveDirection.y = (jumpForce * climbMultiplier);
if (!controller.isGrounded)moveDirection.x = 0f;
}
else if (LadderClimb.canClimb && !reverseClimbing) //Go Down
{
motion = true;
moveDirection.y = 0f;
moveDirection.y = (-jumpForce * climbMultiplier);
if (!controller.isGrounded) moveDirection.x = 0f;
}
}
//Do Nothing (or just look around)
if (LadderClimb.canClimb)
if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S)
&& !Input.GetKey(KeyCode.Space))
motion = false;
}
}
//TThose functions apply the Movement in my character Controller:
//I did put my normal jump function in there too
//Apply Physics
private void PhysicFactors()
{
moveDirection.y = moveDirection.y + (Physics.gravity.y
* gravityScale * Time.deltaTime);
}
//Move
private void Move()
{
controller.Move(moveDirection * Time.deltaTime);
}
//General Jump
private void Jump()
{
moveDirection.y = 0f;
if (Input.GetButtonDown("Jump"))
moveDirection.y = jumpForce;
}
}
I highly believe, this code causes my "teleport on player x. axis
//Jumping from Ladder
if (Input.GetKeyDown(KeyCode.Space))
if(!controller.isGrounded)
if (LadderClimb.canClimb)
{
Debug.Log("intend jump");
motion = true;
moveDirection.x = 0f;
moveDirection.x = (-jumpForce * 10);
moveDirection.y = -jumpForce;
}
moveDirection.x = (-jumpForce * 10);
10决定我要跳到梯子的距离
很明显,我想进入moveDirection.x, 但是当我跳到地面时,
我不想被传送到-JumpForce * 10 然后直接掉到地上
我研究了很多,但无法弄清楚。