I use the following code
Code: Select all
protected internal override void Step()
{
Simulation.Timestep(dt, ThreadDispatcher);
Bepu2ComponentHelper.UpdatePositions();
}
internal static void UpdatePositions()
{
for (var i = 0; i < Simulation.Bodies.Sets.Length; ++i)
{
ref var set = ref Simulation.Bodies.Sets[i];
if (!set.Allocated)
{
continue;
}
for (var bodyIndex = 0; bodyIndex < set.Count; ++bodyIndex)
{
UpdatePose(i, bodyIndex);
}
}
}
static void UpdatePose(int setIndex, int indexInSet)
{
ref var set = ref Simulation.Bodies.Sets[setIndex];
var handle = set.IndexToHandle[indexInSet];
if (setIndex == 0)
{
if (set.Activity [indexInSet].SleepCandidate)
{
return;
}
if (IndexComponent.TryGetValue(handle, out var component))
{
component.PositionChanged();
}
}
}
public void PositionChanged()
{
_preventPositionUpdate = true;
transform.SetPositionOrientation(_bodyReference.Pose.Position.ToSdk(), _bodyReference.Pose.Orientation.ToSdk());
_preventPositionUpdate = false;
}
Is there a list of objects or index that where moved, or an event that an object was moved by the physics?
Also the user can manually move objects, which is the best way to wake up a sleeping object?