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
在这里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