XNA prevent往下走斜坡或向上过于陡峭的山峰 [英] xna prevent to go down slopes or up hills that are too steep

查看:139
本文介绍了XNA prevent往下走斜坡或向上过于陡峭的山峰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能prevent往下走斜坡或最多是在高度图地形过于陡峭的山峰? 我有一个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?

推荐答案

我会避免上升/运行Calcs(计算),因为它们可能会产生一个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 prevent往下走斜坡或向上过于陡峭的山峰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆