Roland Posted September 10, 2016 Share Posted September 10, 2016 Can anyone give some directions on when those should be used. What's the difference. I have in the example's that some actions are programmed in UpdateWorld and some in UpdatePhysics. I have a problem understanding the rule what to do where. Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
reepblue Posted September 11, 2016 Share Posted September 11, 2016 UpdatePhysics is when the Physics calculation is being ticked while Updateworld is once per frame. If you want something consistent regardless of framerate (such as fading out and such) use UpdatePhysics, Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Thirsty Panther Posted September 11, 2016 Share Posted September 11, 2016 My understanding of it is that update world occurs once every loop of your code. So navigation, particle emitter etc are acted out. While update physics occurs depending on the the speed of the CPU and happens every 2nd or 3rd loop of your main code. This takes care of movement and collisions of your models. http://www.leadwerks.com/werkspace/topic/11632-updatephysics-vs-updateworld/ Interestingly there is no info on Update Physics in the API. Quote Link to comment Share on other sites More sharing options...
Rick Posted September 11, 2016 Share Posted September 11, 2016 I believe UpdatePhysics() is called x times per second (30 or 60) where UpdateWorld() is called every cycle (dependent on how fast the CPU is). So when inside UpdateWorld() you want to use the speed in your movement calcs, but in UpdatePhysics() you know it'll be called x times per second and can rely on that. That means it may get called multiple times per frame or skip being called as it all depends on the CPU and how slow/fast it is to maintain the x times per second. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted September 11, 2016 Share Posted September 11, 2016 Interestingly there is no info on Update Physics in the API. Yeah, this is the first thing I tried when I saw the thread. So: unofficial or undocumented? I'd love not having to use Time::GetSpeed() if there's a safe way to do it. There is this though: http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entityupdatephysicshook-r62 Quote Link to comment Share on other sites More sharing options...
Roland Posted September 11, 2016 Author Share Posted September 11, 2016 Thanks all for the input. It makes it a bit clearer what the difference between the two callbacks are. As I have it now I have mouse-smoothing and such in UpdateWorld, seems that it would be better to have that in UpdatePhysics if I understand this correctly. Same for updating animations I guess. Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Josh Posted September 22, 2016 Share Posted September 22, 2016 Well, your mouse input could be read every update with UpdatePhysics, and it would be running at a constant 60 FPS, so no modulation is needed by the timing. However, this function can be skipped some frames, which would result in jittering motion. You can get the mouse input every frame and then smooth it out when you apply it in the UpdateWorld function. This is how the physics systems makes motion smooth all the time, regardless of how fast your game runs. For example, the motion will be smooth even if your game is running at 120 FPS, because the motion is interpolated between the previous two frames of data. That's fairly complicated stuff and you probably won't need to worry about it. Just remember that physics type stuff can be safeuly and easily handled in the UpdatePhysics() function, and it will always run at a constant speed. For stuff that the user expects to change each frame, like camera motion, UpdateWorld() is a better place to put this code, and you would multiply your values by Time:GetSpeed(). If your code is pure physics stuff, like handling the motion of a door by setting velocity, then put it in UpdatePhysics(). Otherwise UpdateWorld is best. 1 2 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Roland Posted September 22, 2016 Author Share Posted September 22, 2016 Thanks a lot Josh for the explanation Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.