cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

Component Life Cycle Adds FixedUpdate

Open lealzhan opened this issue 2 years ago • 9 comments

lealzhan avatar Aug 31 '23 02:08 lealzhan

I understand it will be harder to achieve on web platform because it's single threaded. @dumganhar @minggo if it's only for physics, can we use worker to run wasm physics module and make fixed update possible ?

pandamicro avatar Aug 31 '23 06:08 pandamicro

There are some issues if using worker:

  • Not all platforms support web worker, how to add this feature for those platforms?
  • The communication between worker and main thread by message may be expensive.

dumganhar avatar Aug 31 '23 06:08 dumganhar

I do not believe a web worker would be necessary. The only thing that is needed is a new director event inside of the while loop in postUpdate of the physics-system. There are currently two director events Director.EVENT_BEFORE_PHYSICS and Director.EVENT_AFTER_PHYSICS. If you simply add a new event right before this.physicsWorld.step then that could work. Director.EVENT_BEFORE_STEP_PHYSICS.

If you wanted to add the fixedUpdate callback in the component, then you could register for this director event in components that define fixedUpdate.

mikecoker avatar Aug 31 '23 13:08 mikecoker

@mikecoker , good point. Also, I think that we should not trigger a user callback outside engine's main loop.

dumganhar avatar Sep 01 '23 02:09 dumganhar

If I'm not mistaken - without fixedUpdate we do not get the relevant positions of objects that are moving with code/physics?

I mean instead of getting 15 FPS in game and seeing the real speed of arrow (it will get the monster in 0.2 seconds) we will get slow-mo version of game where arrow will travel to monster in 3 seconds?

I had this problem with Godot webgl export, but Godot has _physicsProcess which is similar to Unity fixedUpdate. When I started using _physicsProcess in Godot - it fixed the problem.

I really hope Cocos will implement fixedUpdate too. I'm yet to encounter problem with it but I assume it will be the same as in Godot.

idchlife avatar Jan 09 '24 17:01 idchlife

Guys, is it possible to achieve without some patch or update? Like a workaround of some kind.

I'm having my game run slow in some browsers, like slow mode. I would rather have low FPS but position of objects to be true to the time passed.

idchlife avatar Feb 10 '24 08:02 idchlife

Is there any progress made on this issue?

mikecoker avatar Jul 19 '24 21:07 mikecoker

Is there any progress made on this issue?

Currently I have workaround using custom component derived from default one but with fixedUpdate method. Nothing too fancy (simple fixed update implementation), I can share here if you'd like.

idchlife avatar Jul 19 '24 21:07 idchlife

Thanks. I was mostly just wondering if they are planning on supporting this in the engine or if it is DOA. We can work around it, but it would be nice if the engine supported it.

mikecoker avatar Jul 19 '24 21:07 mikecoker