关于用AI寻找到PATH后有时候不运动,立即窗口的路径调试信息
tv3d吧
全部回复
仅看楼主
level 7
关于用AI寻找到PATH后有时候不运动,立即窗口的路径调试信息当给一个对像设了路径后,对像会沿着路径运动,所以 GetPathCurrentNode的值会不断增长,表示对像到达了路径中的某个点.
在这里AI寻找到了路径返回有4个节点的PATH,然后把PATH赋给BODY,重新设置让BODY从0号节点开始运动. tmpDestinationNode= Vector3(EnemyPozX, EnemyPozY, EnemyPozZ) '是敌人的坐标
If Path Is Nothing Then
Set Path = AI.FindNodePath(AI.GetNodePosition(AI.GetNearestNode(Body.GetPosition)), AI.GetNodePosition(AI.GetNearestNode(tmpDestinationNode)), Foundpath)
'上句从角色的位置到敌人返回一条路径
'找到了路
If Foundpath = 1 Then
Path.EnableLooping False
Path.SetPathType TV_PATH_SPLINE
Body.SetPath Path, False
Body.ResetPath 0 '重新设置让BODY从0号节点开始运动.
PathLength = Maths.GetDistanceVec3D(Path.GetNode(Path.GetNodeCount - 1), Path.GetNode(0))
Body.SetPathSpeed 200 / PathLength
Else
'Set Path = Nothing
'Body.SetPath Path, False '消除路径,要不人物不会走了
'Status = "cutenemy"
End If
Else 'NPC在路上行走时 tmpDestinationDirection = Maths.VNormalize(Maths.VSubtract(tmpDestinationNode, Path.GetNode(Body.GetPathCurrentNode)))
AngleZ = Maths.Direction2Ang(tmpDestinationDirection.x, tmpDestinationDirection.z) 'NPC总的行走的方向转化为角度值'
Debug.Print "Body.GetPathCurrentNode = " & Body.GetPathCurrentNode : Debug.Print " Path.GetNodeCount=" & Path.GetNodeCount
If Maths.VCompare(Body.GetPosition, Path.GetNode(Path.GetNodeCount - 1)) Then '到达了路径的最后一个节点
tmpDestinationDirection = Maths.VNormalize(Maths.VSubtract(tmpDestinationNode, Body.GetPosition))
AngleZ = Maths.Direction2Ang(tmpDestinationDirection.x, tmpDestinationDirection.z) 'NPC总的行走的方向转化为角度值'
Status = "cutenemy" '到达了路径终点,把角色状态设为砍人状态
'Debug.Print "设置砍人"
Body.SetPath Nothing, False '消除路径,
End If
End If
问题一,不判断角色到达了路径的终点后,为什么 GetPathCurrentNode会一直增长,到最后会比 GetNodeCount的值还大
问题二,有时NPC在原地跑不动,经DEBUG,是Body.GetPathCurrentNode 这个值没有增长,总为0或者为一个很小的值,但是只要我操作敌人走几步,Body.GetPathCurrentNode 就增长了.
如果是找不到路径,那么PATH还是为空,也把路径设置给BODY了,就是不知道为什么Body.GetPathCurrentNode 有时候不增长.
'立即窗口 debug.print 的信息: Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.801095E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1283187
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.781519E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1255872
Path.GetNodeCount=4
Body.GetPathCurrentNode = .2087086
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.842045E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.830235E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.809272E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.746922E-02
2013年03月29日 11点03分 1
level 7
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.806151E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.825795E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.792954E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.811348E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.821895E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.747462E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.808232E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1256317
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.739753E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.775585E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .0577191
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1255395
Path.GetNodeCount=4
Body.GetPathCurrentNode = .2100916
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.754163E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1258582
Path.GetNodeCount=4
Body.GetPathCurrentNode = .0587708
Path.GetNodeCount=4
Body.GetPathCurrentNode = 6.248738E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1319067
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.750654E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.732084E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .125356
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.763341E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1254143
Path.GetNodeCount=4
Body.GetPathCurrentNode = .0584772
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.740482E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1254882
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.900262E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .0741213
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.749735E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.741509E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.755291E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1251861
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.866246E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1271038
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.756651E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.772151E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 5.809182E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 4.128173E-02
Path.GetNodeCount=4
Body.GetPathCurrentNode = 8.882618E-02 '从这里看上面的DEBUG信息,就知道BODY没有沿路径运动了,在原地踏步..
Path.GetNodeCount=4
Body.GetPathCurrentNode = .1472078
Path.GetNodeCount=4
Body.GetPathCurrentNode = .198838
Path.GetNodeCount=4
Body.GetPathCurrentNode = .2504299
Path.GetNodeCount=4
Body.GetPathCurrentNode = .3017831
Path.GetNodeCount=4
Body.GetPathCurrentNode = .3527087
Path.GetNodeCount=4
Body.GetPathCurrentNode = .4042262
Path.GetNodeCount=4
Body.GetPathCurrentNode = .4560237
Path.GetNodeCount=4
2013年03月29日 11点03分 2
level 7
Body.GetPathCurrentNode = .5073228
Path.GetNodeCount=4
Body.GetPathCurrentNode = .558457
Path.GetNodeCount=4
Body.GetPathCurrentNode = .6096092
Path.GetNodeCount=4
Body.GetPathCurrentNode = .6607168
Path.GetNodeCount=4
Body.GetPathCurrentNode = .7115378
Path.GetNodeCount=4
Body.GetPathCurrentNode = .7627442
Path.GetNodeCount=4
Body.GetPathCurrentNode = .8138838
Path.GetNodeCount=4
Body.GetPathCurrentNode = .8650584
Path.GetNodeCount=4
Body.GetPathCurrentNode = .9159111
Path.GetNodeCount=4
Body.GetPathCurrentNode = .9668539
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.017731
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.068839
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.119841
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.171677
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.223126
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.274575
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.326213
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.377533
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.42949
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.481307
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.532304
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.583479
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.634645
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.684569
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.784546
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.884973
Path.GetNodeCount=4
Body.GetPathCurrentNode = 1.985399
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.085874
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.135913
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.186238
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.236644
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.286852
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.337307
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.387332
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.437297
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.487448
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.537948
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.588356
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.638677
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.739179
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.839033
Path.GetNodeCount=4
Body.GetPathCurrentNode = 2.93906
Path.GetNodeCount=4
Body.GetPathCurrentNode = 3.038615
Path.GetNodeCount=4
Body.GetPathCurrentNode = 3.139167
Path.GetNodeCount=4
2013年03月29日 11点03分 3
1