cocos / cocos-engine

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.
https://www.cocos.com/en/creator
Other
6.76k stars 1.76k forks source link

Component Life Cycle Adds FixedUpdate #16145

Open lealzhan opened 1 year ago

pandamicro commented 1 year ago

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 ?

dumganhar commented 1 year ago

There are some issues if using worker:

mikecoker commented 1 year ago

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.

dumganhar commented 1 year ago

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

idchlife commented 8 months ago

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 commented 6 months ago

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.

mikecoker commented 1 month ago

Is there any progress made on this issue?

idchlife commented 1 month ago

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.

mikecoker commented 1 month ago

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.