3
我該如何防止下坡或山坡上的高度地形太陡峭? 我有一臺在地形上移動的三維攝像機,即使在大斜坡和山坡上也可以在任何地方移動,我該怎麼辦?xna防止下山斜坡或山坡太陡
我該如何防止下坡或山坡上的高度地形太陡峭? 我有一臺在地形上移動的三維攝像機,即使在大斜坡和山坡上也可以在任何地方移動,我該怎麼辦?xna防止下山斜坡或山坡太陡
我會避免上升/運行計算,因爲如果地形是垂直的,他們可以產生NaN。
//currentPosition & targetPosition should be known to you
Vector3 potentialMove = Vector3.Normalize(targetPosition - currentPosition);
float steepness = Vector3.Dot(Vector3.Up, potentialMove);
if(steepness < 0.85f && steepness > -0.85f) // set to taste. 1 is vertically up, 0 is flat, -1 is vert down
{
//allow move
currentPosition = targetPosition
}
你應該預測你要去的地方,如果你試圖在一個方向移動,然後計算出落得如果您當前的點和你的未來點之間的slope太陡:
if(forward key pressed) {
get location I'll end up at
get the Z of that location
calculate slope using rise/run formula
if(slope is too steep) {
don't move
}
else { move to the future location }
}