private void OnCollisionStay(BoxCollider other) { #region ////colliding from above //if (!(Collider.Bottom < other.Top) && lastPosition.Y + Collider.Height <= other.Top) //{ //} //// colliding from beneigh //else if (!(Collider.Top > other.Bottom) && lastPosition.Y >= other.Bottom) //{ //} ////colliding from left or right //else //{ // if (!(other.GameObject is SideScrollPlayer) && !(other.GameObject is WeightedCompanionCube) && other.GameObject.Tag != "Ground") // movement.ResetVelocityX(); // else if (other.GameObject is SideScrollPlayer) // movement.Move(((SideScrollPlayer)other.GameObject).ViewDirection); //} #endregion if (!other.IsTrigger) { if (!(Collider.Bottom < other.Top) && lastPosition.Y + Collider.Height <= other.Top) { if (isGrounded != true) { isGrounded = true; } if (Position.Y != other.GameObject.Position.Y - Collider.Height) { Position.Y = other.GameObject.Position.Y - Collider.Height; } if (movement.Velocity.Y != 0f) { movement.ResetVelocityY(); } } if (other.Contains(Collider)) { if (Position.Y != other.GameObject.Position.Y - Collider.Height) { Position.Y = other.GameObject.Position.Y - Collider.Height; } } } if (other.GameObject is Portal) { float temp = movement.MoveForce; movement.MoveForce = 300; Teleport(other, movement); movement.MoveForce = temp; } }
private void OnCollisionStay(BoxCollider other) { if (!other.IsTrigger) { if (!(Collider.Bottom < other.Top) && (lastPosition.Y + Collider.Height <= other.Top) && isJumping == false) { if (isGrounded != true) { isGrounded = true; } if (Position.Y > other.GameObject.Position.Y - Collider.Height) { Position.Y = other.GameObject.Position.Y - Collider.Height; } if (velocity.Y != 0f) { velocity.Y = 0f; } } if (Position.Y > other.GameObject.Position.Y - Collider.Height) { if (other.Contains(Collider) || Collider.CollidesWithTopOf(other)) { Position.Y = other.GameObject.Position.Y - Collider.Height; } } if (Collider.Bottom > other.Top && Collider.CollidesWithTopOf(other)) { //falling if (velocity.Y > 0f) { if (Position.Y != other.GameObject.Position.Y - Collider.Height) { velocity.Y = -velocity.Y; } } } if (Collider.Top < other.Bottom && Collider.CollidesWithBottomOf(other)) { //rising if (Position.Y != other.GameObject.Position.Y - Collider.Height) { Position.Y = other.GameObject.Position.Y - Collider.Height; } } } }