예제 #1
0
        public static float Detect(IcoSphere obstacle, Player player)
        {
            var r1 = obstacle.GetRadius();
            var r2 = player.GetRadius();
            var d  = (obstacle.GetPosition() - player.GetPosition()).Length;

            return(d - r1 - r2);
        }
예제 #2
0
        private void ApplyCollision(IcoSphere obstacle, Player targetPlayer)
        {
            var detector = CollisionDetector.Detect(obstacle, targetPlayer);

            if (detector > 0.0f)
            {
                return;
            }

            var playerToObstacle = targetPlayer.GetPosition() - obstacle.GetPosition();

            if (!(playerToObstacle.Length > Constants.EPS))
            {
                return;
            }

            var obstacleNormal = playerToObstacle.Normalized();

            targetPlayer.SetPosition((obstacle.GetRadius() + targetPlayer.GetRadius()) * obstacleNormal + obstacle.GetPosition());
        }