public Vector3 Move(Vector3 velocity, float delta) {
Log.Silly("(PlatformerCollider2D) Move({0}, {1}, {2})", gameObject.name, velocity.ToString("F4"), delta);
// swap layers, this makes possible to collide with something inside
// my own layer like boxes
previousLayer = gameObject.layer;
gameObject.layer = 2; // Ignore Raycast
UpdateRaycastOrigins();
// debug
var b = bounds;
b.Draw(transform, new Color(1,1,1, 0.25f));
b.center += velocity;
b.Draw(transform, new Color(0,0,1, 0.5f));
b.Expand(minDistanceToEnv * 2);
//b.center -= new Vector3(minDistanceToEnv, minDistanceToEnv, 0);
b.Draw(transform, new Color(0,0,1, 0.75f));
// set previous collisions and reset current one
pCollisions = collisions.Clone();
collisions.Reset();
// Climb or descend a slope if in range
if (enableSlopes) {
UpdateCurrentSlope(velocity);
// TODO PERF add: pCcollisions.below, so wont be testing while falling
// if (collisions.slopeAngle != 0 && pCollisions.below) {
if (collisions.slopeAngle != 0) {
//Debug.Log("velocity before" + velocity.ToString("F4"));
ClimbSlope(ref velocity);
DescendSlope(ref velocity);
//Debug.Log("velocity after" + velocity.ToString("F4"));
}
}
// be sure we stay outside others colliders
if (!disableWorldCollisions) {
ForeachLeftRay(skinWidth, ref velocity, HorizontalCollisions);
ForeachRightRay(skinWidth, ref velocity, HorizontalCollisions);
if (velocity.y > 0) {
ForeachFeetRay(skinWidth, ref velocity, VerticalCollisions);
ForeachHeadRay(skinWidth, ref velocity, VerticalCollisions);
} else {
ForeachFeetRay(skinWidth, ref velocity, VerticalCollisions);
}
}
if (Math.Abs(velocity.x) < minTranslation) {
velocity.x = 0;
}
if (Math.Abs(velocity.y) < minTranslation) {
velocity.y = 0;
}
if (useRigidbody2D) {
rigidBody2D.velocity = velocity / delta;
} else {
transform.Translate(velocity);
}
collisions.velocity = velocity;
ConsolidateCollisions();
gameObject.layer = previousLayer;
b = bounds;
b.center += velocity;
b.Draw(transform, new Color(0,1,1,0.25f));
Log.Silly("(PlatformerCollider2D) Moved({0}, {1}, {2})", gameObject.name, velocity.ToString("F4"), delta);
return velocity;
}