本文介绍了xna 防止下坡或上坡太陡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何防止在高度图地形上下坡或上坡太陡?我有一个可以在地形上移动的 3d 相机,现在它可以在任何地方移动,即使是在大斜坡和太陡的山坡上,我该怎么办?
how can i prevent to go down slopes or up hills that are too steep on heightmap terrain?I have a 3d camera that moves on a terrain, it now moves on any place even on big slopes and on hills that are too steep, what can I do?
推荐答案
我会避免上升/运行计算,因为如果地形是垂直的,它们可能会产生 NaN.
I would avoid rise/run calcs as they could produce a NaN if terrain is vertical.
//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
}
这篇关于xna 防止下坡或上坡太陡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!