关于unity里的update,fixedupdate

更新时间:2023-08-08 04:57:07 阅读: 评论:0

关于unity⾥的update,fixedupdate
写春天pvd是什么意思Update⽅法会在每⼀帧执⾏,具体多长时间会调⽤⼀次取决于你游戏的帧速。
FixedUpdate⽅法是固定时间来执⾏,它不管你当前游戏的运⾏速度等情况,它每秒会调⽤1/time.fixeddeltatime次。具体的时间长度设置在unity编辑器的菜单Edit->Project Settings->Time
输⼊你不能放到FixedUpdate⾥做,因为你有可能丢失(即没有捕获)某⼀帧的输⼊事件。固定时间刷新这个概念只能⽤于更新连续性的物理系统。对于⾮连续性的物理系统,类似射线检测函数Physics.Raycast,以及Rigidbody.AddForce都应该在update⾥做。unity其实是想后者放在fixed update⾥做的。
物理系统的衡量是以时间为单位的,例如每秒多少多少,这样⾮常有必要放到 fixed update,做到与帧率⽆关才不会让物理系统看起来怪怪的。
不二法门是什么意思One huge reason why only continuous physics belong in FixedUpdate is the actual nature of FixedUpdate. Other answers have mentioned how FixedUpdate is called at a fixed interval, but that's slightly misleading. In reality, a script is pasd a time in Time.deltaTime/Time.fixedDeltaTime* which doesn't correspond directly to the actual time between calls, but rather the simulated time between calls.
(*Time.deltaTime and Time.fixedDeltaTime are the same value when called in FixedUpdate[Unity is able to tell if the current call
to Time.deltaTime originated during FixedUpdate and returns Time.fixedDeltaTime])
Naturally the same way Update can't be called in a constant manner becau of varying performance, neither can FixedUpdate. The key difference is, each frame, if FixedUpdate hasn't been getting called often enough to average out to the correct interval between calls, it gets called multiple times (or isn't called the average is too high). This is what the refer to in saying that FixedUpdate can be called multiple times a frame:
... FixedUpdate: FixedUpdate is often called more frequently than Update. It can be called multiple times per frame, if the frame rate is low and it may not be called between frames at all if the frame rate 强调句句型
This doesn't affect Physics becau of the nature of the rest of the execution order and the engine, but just about anything el you put
in FixedUpdate will be affected, and it will cau issues.
孕妇能吃花椒吗For example, if you put AI processing inside FixedUpdate there's no reason to assume that the AI won't skip updates for multiple frames in a row. Additionally, each time `FixedUpdate falls behind, your AI will update multiple times in a single frame before things like physics and player input/movement are procesd, which is a waste of processing at the very least, but is also extremely likely to cau hard to track down bugs and erratic behavior.
If you need to do something at a fixed interval u other methods Unity provides such as Coroutines and InvokeRepeating.
佘东鹏>轻色
And a small note on Time.deltaTime and when to u it:
The easiest way to describe the effect of Time.deltaTime is it changes a number from unit per frame, to unit per cond. For example, if you have a script with something like transform.Translate(Vector3.up * 5) in Update, you're esntially moving the transform at a rate of 5 meters per frame. That means if framerate is low the movement is slower, and if framerate is high, the movement is faster.
If you take that same code and change it to transform.Translate(Vector3.up * 5 * Time.deltaTime) , the object is being moved at a rate of 5 meters per cond. That means no matter the framerate, the
object will move 5 meters every cond (but the slower the framerate, the jumpier the object's movement will appear since it still moves the same amount every X conds)
In general, you want your movement to be per cond. That way no matter what speed the computer is going at, your physics/movement will behave the same way, and you won't have strange bugs popping up on slower devices.观音桥好吃街
And there's no point in using it in FixedUpdate. Becau of what I mentioned above, you'll get the same value each call (the Fixed Update Timestep value), and it won't do anything to your values. Movement/Physics defined in FixedUpdate is already going to be in units per cond so you don't need it.

本文发布于:2023-08-08 04:57:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1106806.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:3442中文资料
标签:系统   时间   物理   速度   游戏   没有   丢失   连续性
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图