关于路径速度的问题
tv3d吧
全部回复
仅看楼主
level 7
虽然我们让一个ACTOR设置恒定的 SetPathSpeed 0.1,但角色在运动过程中从一个节点到另一个节点的速度还是不相同,两个节点近时速度慢,两个节点远时速度快。
循环之前:
Set Barney = Scene.CreateActor
Barney.LoadTVA "media/Barney.tva"
Barney.SetPosition 0, 35, 0
Barney.SetRotation 0, 90, 0
Barney.SetAnimationByName "walk"
Barney.PlayAnimation 1
Set aPath = Scene.CreatePath
Randomize
aPath.AddPathNode Vector3(0, 35, 0)
aPath.AddPathNode Vector3(Int(Rnd * 1001 - 500), 35, Int(Rnd * 1001 - 500))
aPath.SetPathType TV_PATH_LINEAR
aPath.EnableLooping False '是否路沿径返回
Barney.SetPath aPath, False
Barney.SetPathSpeed 0.1
'循环之中,角色不停的走动
'先保存角色的历史足迹
For i = 0 To 2
BarneyPozHistory(0) = BarneyPozHistory(1)
BarneyPozHistory(1) = BarneyPozHistory(2)
BarneyPozHistory(2) = BarneyPozHistory(3)
Next
BarneyPozHistory(3) = Barney.GetPosition
Barney.SetRotation 0, Math.Direction2Ang(BarneyDirecton.x, BarneyDirecton.z) + 90, 0
If Not Math.VCompare(Barney.GetPosition, aPath.GetNode(aPath.GetNodeCount - 1)) Then '当前位置向量和最后一个向量比较,不相同则自己计算方向向量
BarneyDirecton = Math.VNormalize(Math.VSubtract(Barney.GetPosition, BarneyPozHistory(2)))
Else
'到达了最后一个节点,
BarneyDirecton = Math.VNormalize(Math.VSubtract(aPath.GetNode(aPath.GetNodeCount - 1), aPath.GetNode(aPath.GetNodeCount - 2)))
aPath.MoveNode 0, Barney.GetPosition
aPath.MoveNode 1, Vector3(Int(Rnd * 1001 - 500), 35, Int(Rnd * 1001 - 500))
Debug.Print Barney.GetPathCurrentNode
Barney.ResetPath 0
End If
'''有什么方法可以上一个角色以恒定的速度运动呢??
2013年03月29日 02点03分 1
level 7
谢谢二楼,三楼,我已搞定,
aPath.MoveNode 0, Barney.GetPosition
tmpx = Int(Rnd * 1001 - 500)
tmpy = 35
tmpz = Int(Rnd * 1001 - 500)
aPath.MoveNode 1, Vector3(tmpx, tmpy, tmpz)
PathLength = Math.GetDistanceVec3D(Vector3(tmpx, tmpy, tmpz), Barney.GetPosition) '关键是这
Debug.Print Barney.GetPathCurrentNode
Barney.ResetPath 0
Barney.SetPathSpeed 20 / PathLength '关键是这
2013年03月29日 08点03分 4
1