Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public override void InitializeAcademy()
Monitor.verticalOffset = 1f;
Physics.defaultSolverIterations = 12;
Physics.defaultSolverVelocityIterations = 12;
Time.fixedDeltaTime = 0.01333f; // (75fps). default is .2 (60fps)
Time.fixedDeltaTime = 0.01333f; // (75fps). default is .02 (60fps)
Copy link
Contributor

Choose a reason for hiding this comment

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

<opinion>
I do think we should avoid changing those in our environments.
</opinion>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know the history of them; since the scenes that override them are using ragdolls, I assume it was to improve stability. It might all change with the physx changes anyway.

Time.maximumDeltaTime = .15f; // Default is .33
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using UnityEngine;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is SimulationSettingsOverrides more appropriate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

Copy link
Contributor

Choose a reason for hiding this comment

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

This is directly modifying what unity calls ProjectSettings, maybe ProjectSettingsOverrides?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That works for me too. Since this will only be used in our scenes, I'm less worried about the naming or making sure that it handles all possible cases.

using MLAgents;

public class SettingsOverrides : MonoBehaviour
{
// Original values
Vector3 m_OriginalGravity;
float m_OriginalFixedDeltaTime;
float m_OriginalMaximumDeltaTime;
int m_OriginalSolverIterations;
int m_OriginalSolverVelocityIterations;

public float gravityMultiplier = 1.0f;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if we should have gravity multiplier or gravity setting (with default at -9.81)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the scenes today use a multiplier (but FloatPropertiesChannel use the negative of the value)

public float fixedDeltaTime = .02f;
public float maximumDeltaTime = .33f;

[Header("Advanced physics settings")]
public int solverIterations = 6;
public int solverVelocityIterations = 1;

public void Awake()
{
// Save the original values
m_OriginalGravity = Physics.gravity;
Debug.Log($"Time.fixedDeltaTime = {Time.fixedDeltaTime} Time.maximumDeltaTime={Time.maximumDeltaTime}");
m_OriginalFixedDeltaTime = Time.fixedDeltaTime;
m_OriginalMaximumDeltaTime = Time.maximumDeltaTime;
m_OriginalSolverIterations = Physics.defaultSolverIterations;
m_OriginalSolverVelocityIterations = Physics.defaultSolverVelocityIterations;

// Override
Physics.gravity *= gravityMultiplier;
Time.fixedDeltaTime = fixedDeltaTime;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most scenes only care about gravity, but Crawler and Walker override these deltaTime and solver iterations settings.

Time.maximumDeltaTime = maximumDeltaTime;
Physics.defaultSolverIterations = solverIterations;
Physics.defaultSolverVelocityIterations = solverVelocityIterations;

var academy = FindObjectOfType<Academy>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will eventually be replaced with singleton access.

academy.LazyInitialization();

academy.FloatProperties.RegisterCallback("gravity", f => { Physics.gravity = new Vector3(0, -f, 0); });
}

public void OnDestroy()
{
Physics.gravity = m_OriginalGravity;
Time.fixedDeltaTime = m_OriginalFixedDeltaTime;
Time.maximumDeltaTime = m_OriginalMaximumDeltaTime;
Physics.defaultSolverIterations = m_OriginalSolverIterations;
Physics.defaultSolverVelocityIterations = m_OriginalSolverVelocityIterations;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override void InitializeAcademy()
// make walker joint calculations more accurate.
Physics.defaultSolverIterations = 12;
Physics.defaultSolverVelocityIterations = 12;
Time.fixedDeltaTime = 0.01333f; //(75fps). default is .2 (60fps)
Time.fixedDeltaTime = 0.01333f; //(75fps). default is .02 (60fps)
Time.maximumDeltaTime = .15f; // Default is .33

FloatProperties.RegisterCallback("gravity", f => { Physics.gravity = new Vector3(0, -f, 0); });
Expand Down