Skip to content
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

offgrid friction in island solver #5263

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Robust.Shared/Physics/Systems/SharedPhysicsSystem.Island.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ internal record struct IslandData(
private const int VelocityConstraintsPerThread = 16;
private const int PositionConstraintsPerThread = 16;

public delegate void LinearDampingOverrideHandler(ref Entity<PhysicsComponent, TransformComponent> entity, ref float? linearDampingOverride);

/// <summary>
/// Invoked to allow content to override linear damping for objects.
/// </summary>
public event LinearDampingOverrideHandler? OnGetLinearDampingOverride;

#region Setup

private void InitializeIsland()
Expand Down Expand Up @@ -720,8 +727,9 @@ private void SolveIsland(
for (var i = 0; i < island.Bodies.Count; i++)
{
var body = island.Bodies[i];
var xform = xformQuery.GetComponent(body.Owner);
var (worldPos, worldRot) =
_transform.GetWorldPositionRotation(xformQuery.GetComponent(body.Owner), xformQuery);
_transform.GetWorldPositionRotation(xform, xformQuery);

var transform = new Transform(worldPos, worldRot);
var position = Physics.Transform.Mul(transform, body.LocalCenter);
Expand All @@ -744,7 +752,12 @@ private void SolveIsland(

angularVelocity += body.InvI * body.Torque * data.FrameTime;

linearVelocity *= Math.Clamp(1.0f - data.FrameTime * body.LinearDamping, 0.0f, 1.0f);
float? linearDampingOverride = null;
var entity = new Entity<PhysicsComponent, TransformComponent>(body.Owner, body, xform);
OnGetLinearDampingOverride?.Invoke(ref entity, ref linearDampingOverride);
var linearDamping = linearDampingOverride ?? body.LinearDamping;

linearVelocity *= Math.Clamp(1.0f - data.FrameTime * linearDamping, 0.0f, 1.0f);
Comment on lines +755 to +760
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more questions:

  1. Do you have the content code that will be using this PRd? As it looks like the linked content PR doesn't use it.
  2. Does just subscribing to entity parent changes and using the body's lineardamping work? As this will also severely impact servers like RMC14 with the overhead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. the linked content PR uses the OnGetLinearDampingOverride.
  2. i don't follow what you mean with the suggestion of using the parent.

angularVelocity *= Math.Clamp(1.0f - data.FrameTime * body.AngularDamping, 0.0f, 1.0f);
}

Expand Down
Loading