Jump to content

UpdateWorld vs UpdatePhysics


Roland
 Share

Recommended Posts

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,

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

  • 2 weeks later...

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.

  • Like 1
  • Upvote 2

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...