Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private bool ResolveStaticCollisions(BSActorCollisionInfo actor)
- {
- actor.staticConstraints.Clear();
- List<BSCollisionConstraint> newConstraints;
- int iterations = 10;
- while (iterations-- > 0)
- {
- newConstraints = CalculateConstraints(actor);
- if (newConstraints.Count <= 0)
- break;
- Vector2 moveVec = actor.newPos - actor.lastTickPos;
- Vector2 correction = Vector2.zero;
- foreach (BSCollisionConstraint constraint in newConstraints)
- {
- Vector2 penetration = constraint.normal * constraint.penetration;
- //float len2 = correction.sqrMagnitude;
- //if (len2 > Mathf.Epsilon)
- // penetration -= (Vector2.Dot(correction, penetration) / len2) * correction;
- correction += penetration;
- actor.staticConstraints.Add(constraint);
- }
- actor.newPos += correction;
- actor.lastTickPos = actor.newPos;
- moveVec = actor.ClampVector2ToConstraints(moveVec + correction, false);
- actor.newPos += moveVec;
- }
- Debug.Log(iterations);
- return actor.staticConstraints.Count > 0;
- }
Add Comment
Please, Sign In to add comment