Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
CharacterController.velocity 速度
# [CharacterController](CharacterController.html).velocity 速度 var *velocity* : [Vector3](../Vector3/Vector3.html) *Description* 描述 The current relative velocity of the Character (see notes). 角色当前的相对速度(参见注解)。 This allows you to track how fast the character is actually walking for example when he is stuck at a wall this value will be the zero vector. 它允许你追踪角色究竟移动有多快,例如,当他被卡在墙壁里,这个值将变为 0 向量。 Note: The velocity returned is simply the difference in distance for the current timestep before and after a call to CharacterController.Move or CharacterController.SimpleMove. The velocity is relative because it won't track movements to the transform that happen outside of the CharacterController (e.g. character parented under another moving Transform, such as a moving vehicle). 注解:返回速度在调用 CharacterController.Move 或者 CharacterController.SimpleMove 之前和之后的时刻是不同的。速度是相对的,因为它不会追踪发生在 CharacterController 之外的变换的运动(例如,角色继承于另一个运动着的变换之下,比如一个运动着的车辆)。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { CharacterController controller = GetComponent<CharacterController>(); Vector3 horizontalVelocity = controller.velocity; horizontalVelocity = new Vector3(controller.velocity.x, 0, controller.velocity.z); float horizontalSpeed = horizontalVelocity.magnitude; float verticalSpeed = controller.velocity.y; float overallSpeed = controller.velocity.magnitude; } } ``` ``` function Update () { var controller : CharacterController = GetComponent(CharacterController); var horizontalVelocity : Vector3 = controller.velocity; horizontalVelocity = Vector3(controller.velocity.x, 0, controller.velocity.z); // The speed on the x-z plane ignoring any speed //忽略Y轴的X-Z平面上的速度。 var horizontalSpeed : float = horizontalVelocity.magnitude; // The speed from gravity or jumping //重力或者跳跃引起的速度。 var verticalSpeed : float = controller.velocity.y; // The overall speed //总体速度。 var overallSpeed : float = controller.velocity.magnitude; } ```
da
2022年5月17日 17:35
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码