-
Notifications
You must be signed in to change notification settings - Fork 41
Use Position and Rotation instead of GlobalTransform (Based off PR #61) #81
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
Changes from 14 commits
a0743b8
d890cd9
31dafba
6afb0a6
2c955b5
3bc32f8
a10433c
5492484
0f28eb6
e8425b0
e4d1d3b
6099a73
c4d7909
009e3d1
152fce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| #[cfg(feature = "avian2d")] | ||
| use avian2d::{prelude as avian, prelude::*, schedule::PhysicsSchedule}; | ||
| use avian2d::{prelude as avian, prelude::*}; | ||
| use bevy::ecs::schedule::ScheduleLabel; | ||
| use bevy::prelude::*; | ||
| #[cfg(feature = "rapier2d")] | ||
|
|
@@ -22,6 +22,7 @@ use tnua_demos_crate::app_setup_options::{AppSetupConfiguration, ScheduleToUse}; | |
| use tnua_demos_crate::character_control_systems::info_dumpeing_systems::character_control_info_dumping_system; | ||
| use tnua_demos_crate::character_control_systems::platformer_control_systems::{ | ||
| apply_platformer_controls, CharacterMotionConfigForPlatformerDemo, FallingThroughControlScheme, | ||
| JustPressedCachePlugin, | ||
| }; | ||
| use tnua_demos_crate::character_control_systems::Dimensionality; | ||
| use tnua_demos_crate::level_mechanics::LevelMechanicsPlugin; | ||
|
|
@@ -101,10 +102,10 @@ fn main() { | |
| app.add_plugins(TnuaControllerPlugin::new(FixedUpdate)); | ||
| app.add_plugins(TnuaCrouchEnforcerPlugin::new(FixedUpdate)); | ||
| } | ||
| #[cfg(any(feature = "avian", feature = "avian"))] | ||
| #[cfg(feature = "avian")] | ||
| ScheduleToUse::PhysicsSchedule => { | ||
| app.add_plugins(TnuaControllerPlugin::new(PhysicsSchedule)); | ||
| app.add_plugins(TnuaCrouchEnforcerPlugin::new(PhysicsSchedule)); | ||
| app.add_plugins(TnuaControllerPlugin::new(FixedUpdate)); | ||
|
||
| app.add_plugins(TnuaCrouchEnforcerPlugin::new(FixedUpdate)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -129,11 +130,14 @@ fn main() { | |
| ScheduleToUse::Update => Update.intern(), | ||
| ScheduleToUse::FixedUpdate => FixedUpdate.intern(), | ||
| #[cfg(feature = "avian")] | ||
| ScheduleToUse::PhysicsSchedule => PhysicsSchedule.intern(), | ||
| // `PhysicsSchedule` is `FixedPostUpdate` by default, which allows us | ||
| // to run user code like the platformer controls in `FixedUpdate`, | ||
| // which is a bit more idiomatic. | ||
| ScheduleToUse::PhysicsSchedule => FixedUpdate.intern(), | ||
| }, | ||
| apply_platformer_controls.in_set(TnuaUserControlsSystemSet), | ||
| ); | ||
| app.add_plugins(LevelMechanicsPlugin); | ||
| app.add_plugins((LevelMechanicsPlugin, JustPressedCachePlugin)); | ||
| #[cfg(feature = "rapier2d")] | ||
| { | ||
| app.add_systems(Startup, |mut cfg: Single<&mut RapierConfiguration>| { | ||
|
|
||
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.
Isn't the
PhysicsSchedulea schedule of its own, separate from theFixedUpdate?Uh oh!
There was an error while loading. Please reload this page.
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.
Not sure what @janhohenheim meant by PhysicsSchedule being FixedUpdate by default
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.
Maybe that the default in Avian is
FixedUpdatebut usually you'd want to usePhysicsSchedule?This is kind of important, both because the documentation needs to be correct and because it affects the
ScheduleToUse::PhysicsScheduleoption in the demos. I'll try to ping him on Discord.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.
Hey hey everyone. I was not active much in the Bevy space for some months due to academia, so what I'm writing now might not be accurate. But as I remember it, I was looking at
PhysicsScheduleas basically a generic label / wrapper / "variable" for the actual schedule. What the actual schedule was, I determined by looking atPhysicsSchedulePlugin .schedulewhich back then wasFixedUpdateby default (nowFixedPostUpdate).It's very very possible that I misunderstood / misunderstand how the schedule hierarchy precisely works in Bevy, so if you think this sounds somewhat wrong, it probably is :D
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.
That's weird. I thought the point of the
PhysicsSchedulewas supposed to run in its own frequency, which means its runner was supposed to run it multiple times, or not at all, depending on how much time has passed since the last time it was ran. In other words - even if it runs inPostUpdatethePhysicsScheduleitself still gets fixed frame time.But not it looks like
PhysicsScheduleis mostly about not running it if Avian is paused and about replacing theTimeresource while it runs?Uh oh!
There was an error while loading. Please reload this page.
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.
@idanarye The point of the
PhysicsScheduleis just to advance the whole physics simulation by one step, using the delta time stored in theTimeresource. The schedule is independent of how often and in what way it is run; you could run it with a fixed time step, a variable time step, or even run it manually for e.g. networking purposes.Avian 0.2 did indeed change how the default scheduling is set up. Previously, Avian managed its own fixed time step in
PostUpdate, but this had unnecessary complexity, footguns (ex: duplicate fixed time steps when running physics inFixedUpdate, and having to useTime::fixed_once_hz), several bugs, and it was overall strange to emulate a custom fixed time step when Bevy already has a first-party one. Running physics afterUpdatewas also kind of strange; both Unity and Godot run it before, near the end ofFixedUpdate/_physics_process.With the new scheduling, the
PhysicsScheduleis run inFixedPostUpdateby default, makingFixedUpdatethe natural place for most user gameplay logic and movement systems, except of course for things like camera movement or interpolation which should typically run every frame for smooth and responsive results.You can still run physics in e.g.
PostUpdatetoo, but it will use a variable time step withTime<Virtual>since that is the active time resource there. And of course custom scheduling is possible too for additional control.The new scheduling and rationale is covered in all of these:
FixedPostUpdateby default and simplify scheduling avianphysics/avian#457There 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.
My scheduling goals are:
Base on these goals and your description, I'd say the recommended way is to have both
TnuaControllerPluginandTnuaAvian#dPluginusePhysicsScheduleand to put the user control systems underFixedUpdate?Also, regarding the demos, this means that
ScheduleToUse::PhysicsScheduleis meaningless. Instead, for Avian,ScheduleToUse::Updateshould register Avian itself underPostUpdateand the user control systems underUpdatewhileScheduleToUse::FixedUpdateshould register Avian itself underFixedPostUpdateand the user control systems underFixedUpdate- and either way the Tnua plugins should be registered underPhysicsSchedule.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.
@idanarye Is this still blocked by the scheduling choices? I've been using this fork for use with lightyear with success for the last couple months.
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.
@BrainBacon
Pretty much, yes. Not sure if "blocked" is the correct word, since this mainly is about the docs and about the demos and I can always just merge it and fix it myself, but I do want to at least understand it before doing so.
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.
I think I'll just merge it and fix the scheduling (and doc comments)