Guest User

Untitled

a guest
Jan 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1.     private bool ResolveStaticCollisions(BSActorCollisionInfo actor)
  2.  
  3.     {
  4.  
  5.         actor.staticConstraints.Clear();
  6.  
  7.        
  8.  
  9.         List<BSCollisionConstraint> newConstraints;
  10.  
  11.         int iterations = 10;
  12.  
  13.         while (iterations-- > 0)
  14.  
  15.         {
  16.  
  17.             newConstraints = CalculateConstraints(actor);
  18.  
  19.             if (newConstraints.Count <= 0)
  20.  
  21.                 break;
  22.  
  23.            
  24.  
  25.             Vector2 moveVec = actor.newPos - actor.lastTickPos;
  26.  
  27.             Vector2 correction = Vector2.zero;
  28.  
  29.            
  30.  
  31.             foreach (BSCollisionConstraint constraint in newConstraints)
  32.  
  33.             {
  34.  
  35.                 Vector2 penetration = constraint.normal * constraint.penetration;
  36.  
  37.                 //float len2 = correction.sqrMagnitude;
  38.  
  39.                 //if (len2 > Mathf.Epsilon)
  40.  
  41.                 //  penetration -= (Vector2.Dot(correction, penetration) / len2) * correction;
  42.  
  43.                
  44.  
  45.                 correction += penetration;
  46.  
  47.                 actor.staticConstraints.Add(constraint);
  48.  
  49.             }
  50.  
  51.            
  52.  
  53.             actor.newPos += correction;
  54.  
  55.             actor.lastTickPos = actor.newPos;
  56.  
  57.             moveVec = actor.ClampVector2ToConstraints(moveVec + correction, false);
  58.  
  59.             actor.newPos += moveVec;
  60.  
  61.         }
  62.  
  63.        
  64.  
  65.         Debug.Log(iterations);
  66.  
  67.         return actor.staticConstraints.Count > 0;
  68.  
  69.     }
Add Comment
Please, Sign In to add comment