-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PhysicsServer2/3D::space_step()
to step physics simulation manually
#76462
base: master
Are you sure you want to change the base?
Add PhysicsServer2/3D::space_step()
to step physics simulation manually
#76462
Conversation
PhysicsSrver2/3D::space_step()
to step physics simulation manually
b769061
to
2419c05
Compare
void GodotPhysicsServer3D::space_flush_queries(RID p_space) { | ||
// TODO:: | ||
// Like _update_shapes(), to provide controllability for developers, flushing_queries flag should active as a member of space and check it for each space. | ||
// But I'm not sure about that, I am not familiar with multi-threads and the architecture of GodotPhysics. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second point which confuse me.
// TODO:: | ||
// May be let pending_shape_update_list as a member of GodotSpaces3D and update shapes by themselves. | ||
// To avoid effecting Spces which are handled by developer (for lockstep/rollback netcode, it is particularly sensitive). | ||
// If it is unecessary, call _update_shapes() directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first point which confuse me.
2419c05
to
48553ed
Compare
ffbacd8
to
e6573c3
Compare
Hello @Daylily-Zeleen, Saw your PR when making mine ; yours has more general usage but might need some tweaks. |
In my opinion, the PhysicsSpace which be stepped by Instead of call I need people, who familiar with godot physics and server design, to instruct me. |
PhysicsSrver2/3D::space_step()
to step physics simulation manuallyPhysicsServer2/3D::space_step()
to step physics simulation manually
When will this feature be merged? I need this functionality to assist me in implementing my network synchronization. |
@Az-qianchen it hasn't been reviewed yet, so there's no real timeframe for this being merged at the moment, the questions of the OP about some details would need to be resolved as well by someone experienced with the physics If you can test it and give your results and comments it would help the process |
2023-09-13.180402.mp4I am not sure if the way I use is correct, but when I simulation is positive, I can get the correct result. When the value is negative, the result seems to have an error. |
e6573c3
to
c9af63e
Compare
How to step a physics space is not this pr's work. I guess your purpose of passing a negative time to The right way to implement rollback feature is store your physics objects' state, and just restore them when you want to roll back. |
I encountered some obstacles when creating a physical space. Do I need to copy all PhysicsBody3D objects to the new physical space, and all objects must be StaticBody3D to perform space_step() on a single object and obtain the correct collision? |
If your physics object are created as a node (
There has not limit the type of physics objet. I uploaded a testing project for reference.
|
I may not be very clear. In fact, I hope to make a Step Physics Simulation in a certain object in the scene, but in order to get the correct interaction collision, I seem to need to copy a static scene in the simulation space. Or turn PhysicsBody into staticbody in the original scene to prevent being simulated together The following is the code that I tried to transfer the copy to the new physical space, but I still did not think about how to deal with the problem of retaining PhysicsBody and avoiding being simulated together.
|
@Az-qianchen Sorry, I don't think I can help you solve this specific application scenarios. After reading your code, I found that you set the |
Assuming these methods would get/set both the internal state of the Node and the related object in the physics server, this would be a good way of handling the matter. It wouldn't be complete without adding the corresponding |
Don't want to beat a dead horse here, but I strongly recommend that you read this comment if you haven't. I'm not sure about your specific netcode implementation, but if you're doing rollback, you're most likely going to have those issues with this PR. The comment mentions signals, but even if you're not using them, polling for overlapping areas/bodies will still fail to resimulate in certain scenarios. Other things like Once again, this is not to say that this PR isn't useful, or that it shouldn't be merged. Quite the contrary. It's just not sufficient for "full" rollback (i.e. being able to go back to a previous state and reproducing the exact same results in every scenario) |
huh... |
Well, if your game is 2D, you can use You can check it out here if you're interested. The README does a good job of explaining how it works, what it can do and what it can't. |
Unfortunately my project is 3D. Looks like CharacterBody3D does not interface with I hope this thread has an answer or else I'm going to write some C++ haha. |
Current Status of this PR:Rollback is mostly implemented, what remains is updating the code of signals to work with rollback
See godotengine/godot-proposals#2821 (comment) for details on how signals should work. Also there are some spooky It is fair to say OP has neglected this pull request, and anyone can pick this up and hopefully finish it. I am only bumping this to synopsize this PR's status and previous comments, because I am making an online game with rollback which requires physics rollback. And like me, every online action game developer who finishes rollback movement and is about to implement rollback physics, must pause development until a PR such as this merges :( |
I'm not sure it's fair to say OP neglected the PR. He received multiple times feedback on PR, he was waited a very long time for a review by a "physics person" from godot. If they take their time he should be able to take his time too. If this was important to Godot team they would help more and review better/faster and offer more support. It's still not clear what the scope of this PR is, even though the OP clearly wrote he wants to be able to step() the physics server, everyone talks about rollback, which is so out of the scope of this. To me, even if OP doesn't neglect this PR, something that might speed up this PR getting approved would be a more focused approach to this. This PR wants to add step function, and manual stepping. It could be exposed as experimental, and if there are issues fixed after. However it seems Godot team wants to be extra careful, so thats why this might take a very long time (until every possible bug can be caught and fixed). |
Rollback is not that far away from this, depending on your definition of rollback (which there are many)... You save the world state and at any point you go back to it and then use this But yeah, we should stop talking about rollback and netcode when this implements something else (although related). But I can't stress how important this is for multiplayer games, specially when making the jump from P2P games to more serious/competitive games, you NEED to be able to step the physics manually in some way or another, this would MASSIVELY improve what can be achieved with Godot regarding multiplayer games, and it is slowing down/deterring some people from utilizing the engine. |
I beg to differ. This PR is very obviously intended to support rollback. I see the word "rollback" four times in the OP, and both of the linked proposal issues are also specifically discussing networking and rollback. While I do agree that this PR could already be merged if it had a narrower scope (of being able to manually step the physics engine, which is what the changes allow), that narrower scope results in a very niche feature that is not useful to most people. The primary use case for manually stepping the physics engine is for networking support, which we can't do unless we can also roll back the world state and have it step correctly. |
I have to disagree here. Full rollback support is a huge feature by itself, and there are independent use cases for both manually stepping the physics engine and for being able to load/save the internal state of the physics server. Furthermore, allowing saving/loading will probably require quite a bit of work on godot physics and possibly breaking changes in the physics server API (which would affect existing alternative physics engines and everyone who is using them). Considering the current workload of the core team and how much time it has taken for this to be reviewed, I personally think it's better to be able to merge at least part of the work to get the ball rolling instead of waiting for a full rollback implementation to be executed, reviewed, and merged. |
To add onto this, if the blocker is mainly the rollback aspect, it makes sense to split this into two separate PR's. One to focus on adding the manual I come from a Unity background and as far as I know that engine only has a manual step() function without any way to truly roll back to previous states, and that's worked fine for the many networking libraries there, since they all manually implement their own circular buffers for keeping track of past states. Of course a built-in way to get a snapshot of a particular previous physics world state would be nice but I imagine adding that feature and properly testing it would add a ton of overhead to this issue. |
I'm definitely not advocating for a built-in snapshot buffer or automatic rollback system. That would be drastically more complex and way out of scope. My view is that this PR should solve the problem of events not firing correctly in the case that a user builds their own rollback system and attempts to resimulate the world after setting its state back to a previous snapshot. Otherwise, there will be subtle and extremely confusing bugs for anyone attempting to make use of the physics stepping feature without prior knowledge of this Github issue. The point is, we should be able to update transforms and velocities on rigidbodies at any point and then step the physics engine and get a correct result, regardless of what happened the last time the engine was stepped. How would this work internally (for instance, a body is inside a trigger volume on frame 5, then is moved back outside the volume to its position as it was on frame 3, but on the next step it enters the volume again and now the engine doesn't know it should trigger the event)? No clue. I don't know if it's feasible and I'm not sure how other engines handle it. Maybe it would be possible for the user to always roll back 1 frame further than intended and step again from there... but that has its own potential issues 😕 Maybe it would be easiest to provide a way to retrieve a snapshot of all internal physics engine state for the user to store however they think best, then apply that to revert the world state. IMO networking is already difficult enough without merging a known-broken PR and letting people figure out that it's broken for themselves, which is why I'm advocating for figuring out the known issues before merging. |
We need to get all aligned then: This PR only implements a method to step the physics forward (manually), with all that comes with that like triggering events. Let's start testing it and see if we can figure out how to resimulate events/triggers/signals so this PR is working correctly and can be merged. |
Need to rebase on top of
|
@npinsker this pr is deferred from 4.1 to 4.3 and 4.x at last. |
Completely fair (and I agree). I'm mostly leaving the comment for future possible users since I'm building on top of this PR in my own project |
For anyone looking at this PR, know that I believe blocking this PR was not the best move, as @Daylily-Zeleen said, but rather making multiple smaller commits as things develop (instead of waiting for everything to be ready). Also, the community really wants this, as you can see by the support on the PR, but the godot team isn't as interested to offer much help, sadly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, has been thoroughly tested and been working for months in my custom fork of godot.
@@ -935,13 +935,28 @@ | |||
Creates a 2D space in the physics server, and returns the [RID] that identifies it. A space contains bodies and areas, and controls the stepping of the physics simulation of the objects in it. | |||
</description> | |||
</method> | |||
<method name="space_flush_queries" is_experimental="true"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need these to be experimental?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has not been extensively tested, and I would rather mark all added APIs as experimental to reserve the right to break the compatibility by revoking.
I hope that PR will be merged soon, a lot of people are waiting for review from maintainers. Good work my friend. |
So what is the reason that hinders this PR merger? |
They want to hire someone to work on physics first so they review it. |
Haven't hired someone yet to take over the physics part? Didn't the foundation say a few days ago that it was not short of money? . . |
I dont even know who the lead of physics is, i'll ask akien whether they know anything about when this PR is gonna be reviewed. |
This is currently the most discussed PR on the physics topic, why we haven't heard from anyone with the authority to review it? This just implements a function to step the engine physics, it has been tested individually by many people over the last almost 2 years! It is a simple intervention... |
Just so it's clear, if you really want this change, you can most definitely build yourself a custom engine and try it out, or use an addon that might expose this (shameless plug of godot-rapier that exposes this). |
Implement #1373
In #2821, it seems like the topic is quite big, but I think this pr can solve it.
Here is a simple demonstrate video of rollbackable/recordable physics simulation create by this pr:
rollbackable_simulation.mp4
But this pr is not perfect, there has two points which confuse me (I'm not familiar with multi-threads and GodotPhysics), and I mark them at below.
Here is rollback demo:
physics_rollback_test.zip