private bool Moved() { TimePositionInfo LastPosition = timeBuffer.Peek(); return(transform.position != LastPosition.position || transform.rotation != LastPosition.rotation || (rigidBody && (rigidBody.velocity != LastPosition.velocity))); }
/// <summary> /// Dumb (inneficient) mechanism for testing if the object moved since the last frame, since `transform.hasChanged` seems really buggy. /// </summary> /// <returns></returns> private bool MovedSignificantly() { TimePositionInfo LastPosition = timeBuffer.Peek(); return(Vector3.Distance(transform.position, LastPosition.position) > Settings.PositionChangeThreshold || Quaternion.Angle(transform.rotation, LastPosition.rotation) > Settings.RotationChangeThreshold || (rigidBody && Vector3.Distance(rigidBody.velocity, LastPosition.velocity) > Settings.VelocityChangeThreshold)); }
private void Start() { Reset(); InitialPosition = new TimePositionInfo { position = transform.position, rotation = transform.rotation, velocity = rigidBody != null ? rigidBody.velocity : Vector3.zero, framesSpendInThisState = long.MaxValue / 2, // the object has been there 'forever' }; timeBuffer.Push(InitialPosition); }
public void RewindTime() { // we can't go back in time further than the initial position if (!IsAtInitialPosition) { TimePositionInfo pos = timeBuffer.Pop(); transform.position = pos.position; transform.rotation = pos.rotation; if (rigidBody != null) { rigidBody.velocity = pos.velocity; } // push it back if it is still viable if (pos.framesSpendInThisState > 1) { pos.framesSpendInThisState -= 1; timeBuffer.Push(pos); } } }