Exemplo n.º 1
0
    private bool Moved()
    {
        TimePositionInfo LastPosition = timeBuffer.Peek();

        return(transform.position != LastPosition.position ||
               transform.rotation != LastPosition.rotation ||
               (rigidBody && (rigidBody.velocity != LastPosition.velocity)));
    }
Exemplo n.º 2
0
    /// <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));
    }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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);
         }
     }
 }