법선 방향으로 모션의 구성 요소를 제거하는 것이 똑 바르지 만 모션 플레이를 회전시키는 대신 게임 플레이에 적합 할 수 있습니다. 예를 들어, 3 인칭 액션 게임에서는 벽과 다른 경계에 약간 매달리기 쉬울 수 있으므로 플레이어가 의도 한 바를 추측 할 수 있습니다.
// assume that 'normal' is unit length
Vector GetDesired(Vector input, Vector normal) {
// tune this to get where you stop when you're running into the wall,
// vs. bouncing off of it
static float k_runningIntoWallThreshold = cos(DEG2RAD(45));
// tune this to "fudge" the "push away" from the wall
static float k_bounceFudge = 1.1f;
// normalize input, but keep track of original size
float inputLength = input.GetLength();
input.Scale(1.0f / inputLength);
float dot = DotProduct(input, normal);
if (dot < 0)
{
// we're not running into the wall
return input;
}
else if (dot < k_runningIntoWallThreshold)
{
Vector intoWall = normal.Scale(dot);
intoWall.Scale(k_bounceFudge);
Vector alongWall = (input - intoWall).Normalize();
alongWall.Scale(inputLength);
return alongWall;
}
else
{
// we ran "straight into the wall"
return Vector(0, 0, 0);
}
}