TASable now saves linear and angular velocities

This commit is contained in:
alex-kumpula 2023-11-11 18:50:16 -07:00
parent 0bac49d257
commit d3324ad81f
1 changed files with 13 additions and 1 deletions

View File

@ -12,18 +12,24 @@ public partial class TASable : Node
get { return this._assignedRigidBody3D; } get { return this._assignedRigidBody3D; }
} }
// Frame data
public Dictionary<int, Vector3> framePositions = new Dictionary<int, Vector3>(); public Dictionary<int, Vector3> framePositions = new Dictionary<int, Vector3>();
public Dictionary<int, Vector3> frameLinearVelocities = new Dictionary<int, Vector3>();
public Dictionary<int, Vector3> frameAngularVelocities = new Dictionary<int, Vector3>();
public virtual void SaveState(int frame) public virtual void SaveState(int frame)
{ {
this.framePositions[frame] = this.AssignedRigidBody3D.Position; this.framePositions[frame] = this.AssignedRigidBody3D.Position;
this.frameLinearVelocities[frame] = this.AssignedRigidBody3D.LinearVelocity;
this.frameAngularVelocities[frame] = this.AssignedRigidBody3D.AngularVelocity;
} }
public virtual void LoadState(int frame) public virtual void LoadState(int frame)
{ {
this.AssignedRigidBody3D.Position = this.framePositions[frame]; this.AssignedRigidBody3D.Position = this.framePositions[frame];
this.AssignedRigidBody3D.LinearVelocity = this.frameLinearVelocities[frame];
this.AssignedRigidBody3D.AngularVelocity = this.frameAngularVelocities[frame];
} }
@ -36,6 +42,7 @@ public partial class TASable : Node
TAS.FramesRegressed += this.OnFramesRegressed; TAS.FramesRegressed += this.OnFramesRegressed;
TAS.StartedIncrementing += this.OnStartedIncrementing; TAS.StartedIncrementing += this.OnStartedIncrementing;
TAS.StoppedIncrementing += this.OnStoppedIncrementing; TAS.StoppedIncrementing += this.OnStoppedIncrementing;
TAS.FramesReset += this.OnFramesReset;
this.SaveState(0); this.SaveState(0);
} }
@ -67,4 +74,9 @@ public partial class TASable : Node
{ {
this.AssignedRigidBody3D.Freeze = true; this.AssignedRigidBody3D.Freeze = true;
} }
public virtual void OnFramesReset()
{
this.SaveState(0);
}
} }