Skip to content

Commit

Permalink
Add gravity member
Browse files Browse the repository at this point in the history
  • Loading branch information
hwabis committed Aug 20, 2023
1 parent 102ae94 commit 648c6ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public TestSceneRigidBody()
AddStep("Reset bodies", reset);

AddSliderStep("Simulation speed", 0f, 1f, 0.5f, v => sim.SimulationSpeed = v);
AddSliderStep("Gravity", 0f, 10000f, 981f, v => sim.Gravity = v);
AddSliderStep("Restitution", -1f, 1f, 1f, v => restitution = v);
AddSliderStep("Friction", -1f, 5f, 0f, v => friction = v);

Expand Down
7 changes: 6 additions & 1 deletion osu.Framework/Physics/RigidBodySimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public RigidBodySimulation()
/// </summary>
public float SimulationSpeed = 1;

/// <summary>
/// The downward acceleration to apply on all children.
/// </summary>
public float Gravity = 981f;

private readonly List<IRigidBody> toSimulate = new List<IRigidBody>();

/// <summary>
Expand Down Expand Up @@ -69,7 +74,7 @@ private void integrate(float dt)
// apply the state to each drawable in question.
foreach (var d in toSimulate)
{
d.Integrate(new Vector2(0, 981f * d.Mass), 0, dt);
d.Integrate(new Vector2(0, Gravity * d.Mass), 0, dt);
d.ApplyState();
}
}
Expand Down

0 comments on commit 648c6ca

Please sign in to comment.