How do I write a 'fixedupdate' in script2?

Hi.
How do I write a ‘fixedupdate’ in script2?
I wrote in the same way as script1, but it did not work.

Rotate.prototype.fixedUpdate = function(dt) {

I tried the following, but it also didn’t work.

Rotate.prototype.fixedupdate = function(dt) {

Rotate.prototype.Fixedupdate = function(dt) {

Rotate.prototype.FixedUpdate = function(dt) {

In addition, I could not find out in the API reference.

Please tell me how do I write it.

Thanks.

fixedUpdate doesn’t exist in the new scripting system. Can I ask why you need it?

Hi.

Because, I had heard that fixedUpdate is good for physical operation.
http://answers.unity3d.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html

I don’t need to use fixedUpdate in playcanvas?

No, you can happily use the regular update function and the physics simulation works just fine.

Wow, it sounds great!
I’ll change to write the codes on my project to script2.:slight_smile:

Thank you.

Hi @Will im in need of a fixed update, because im working on a game that is not using the regular physics.
So when on some devices the ticks go beyond what they should, breaking my pseudo physics, how can i implement fixed update?

You could implement a fixed time step yourself. Here’s a good article on how to do so http://gafferongames.com/game-physics/fix-your-timestep/.

So just use the regular update method and do the time accumulator as described in the article.

1 Like

Hi, thanks for the link, but i don’t think i understand the code, what is “integrate()” ?
I you could briefly describe how to use this in playcanvas i would highly appreciate it :C

Hey! Is there any plan to bring fixed update back? It was supremely helpful for me since I tend to do a lot of physics modifications. I come from Unity and used it all the time there

Thanks,
Mitch

Unfortunately, there are no plans at this time. The update and physics update tick is tied to the browser requestFrame. So if you want to update the physics, you can use the standard update call

There is actually a difference between normal PC update and a fixed update. Depending on what you do with physics in update method, there may or may not be a divergence in physics simulation on high frame rate screens vs normal 60 fps. The link above is a good example on how you can implement your own fixed update event. If you have a divergence, you can switch to your own event.

You can unsubscribe rigidbody component system from the regular update method and subscribe it to your custom fixed update, something like:

const system = app.systems.rigidbody;
app.systems.off('update', rigidbody.onUpdate, rigidbody);
app.on('my-fixed-update', rigidbody.onUpdate, rigidbody);
2 Likes