获取 NavMeshAgent 组件的当前速度,或者设置一个速度来手动控制代理。
读取变量将基于人群模拟返回代理的当前速度。
设置变量将覆盖模拟(包括:朝着目标移动、避免碰撞和加速控制),并命令导航网格代理直接使用指定的速度进行移动。使用速度控制代理时,代理的移动仍被限制在导航网格上。
直接设置速度可用于实现玩家角色,这些角色正在导航网格上移动并影响其余模拟人群。另外,将优先级设置为高(较小的值代表较高的优先级)将会使其他模拟代理更急切地避开玩家控制的代理。
建议在手动控制代理时设置每一帧的速度,并且如果释放控制以进行模拟,将速度设置为零。如果将代理的速度设置为某个值,然后停止更新,模拟将会从这里进行提取,并且代理将缓慢减速(假设没有设置目标)。
请注意,读取速度时将始终从模拟返回值。如果您设置了值,设置效果会在下次更新时显示。由于返回的速度来自于模拟(包括规避和碰撞处理),它可能会不同于您设置的值。
速度以每秒的距离单位来指定(与物理学相同),并在全局坐标系中表示。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.