Ejemplo n.º 1
0
        private void InitClimbReachableNodes()
        {
            foreach (ClimbGroup climbGroup in CurrClimbGroup)
            {
                List <Collidable> climbCollidables     = climbGroup.ClimbCollidables;
                Collidable        upperClimbCollidable = climbCollidables[0];
                foreach (var navGraphNode1 in NavGraphNodes)
                {
                    CollidableResults result1 = upperClimbCollidable.CheckForCollision(navGraphNode1.Platform, Vector3.Zero);
                    //check which platform intersects the upper part of the climbable
                    if (result1.Intersect && upperClimbCollidable.MaxHeight >= navGraphNode1.Platform.MaxHeight - 10 && navGraphNode1.Platform.MinWidth <= upperClimbCollidable.MinWidth + 20 && navGraphNode1.Platform.MaxWidth >= upperClimbCollidable.MaxWidth - 20)
                    {
                        Vector2    startPos             = new Vector2(upperClimbCollidable.Center.X, upperClimbCollidable.MinHeight);
                        Collidable lowerClimbCollidable = climbCollidables[climbCollidables.Count - 1];
                        foreach (var navGraphNode2 in NavGraphNodes)
                        {
                            if (navGraphNode1 == navGraphNode2)
                            {
                                continue;
                            }
                            CollidableResults result2 = lowerClimbCollidable.CheckForCollision(navGraphNode2.Platform,
                                                                                               Vector3.Zero);
                            //check which platform intersects the lower part of the climbable
                            if (result2.Intersect && lowerClimbCollidable.MaxHeight < navGraphNode2.Platform.MaxHeight)
                            {
                                Vector2 endPos = new Vector2(lowerClimbCollidable.Center.X,
                                                             navGraphNode2.Platform.MinHeight);

                                if (startPos.Y < endPos.Y)
                                {
                                    navGraphNode1.ReachableNodes.Add(
                                        new Tuple <NavGraphNode, Vector2, Vector2>(navGraphNode2,
                                                                                   startPos - new Vector2(0, 20),
                                                                                   endPos - new Vector2(0, 20)));
                                    navGraphNode2.ReachableNodes.Add(
                                        new Tuple <NavGraphNode, Vector2, Vector2>(navGraphNode1,
                                                                                   endPos - new Vector2(0, 120),
                                                                                   startPos - new Vector2(0, 20)));
                                }
                                else
                                {
                                    navGraphNode1.ReachableNodes.Add(
                                        new Tuple <NavGraphNode, Vector2, Vector2>(navGraphNode2,
                                                                                   startPos - new Vector2(0, 120),
                                                                                   endPos - new Vector2(0, 20)));
                                    navGraphNode2.ReachableNodes.Add(
                                        new Tuple <NavGraphNode, Vector2, Vector2>(navGraphNode1,
                                                                                   endPos - new Vector2(0, 20),
                                                                                   startPos - new Vector2(0, 20)));
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static bool CheckIfInsideClimbingArea(Collidable ray, Collidable collidable)
        {
            var rayCastResult = ray.CheckForCollision(collidable, Vector3.Zero);

            return(rayCastResult.Intersect);
        }
Ejemplo n.º 3
0
        public static CollidableResults DetectSlope(Collidable ray1, Collidable ray2, Collidable collidable)
        {
            CollidableResults rayCastCollisionResult = new CollidableResults()
            {
                Intersect       = false,
                HitPoint        = Vector3.Zero,
                CollisionNormal = Vector3.Zero
            };

            if (ray1.Points.Count > 2 || ray2.Points.Count > 2)
            {
                return(null);
            }



            var  rayCastResult1   = ray1.CheckForCollision(collidable, Vector3.Zero);
            var  rayCastResult2   = ray2.CheckForCollision(collidable, Vector3.Zero);
            bool slopeOnHitPoint1 = false;
            bool slopeOnHitPoint2 = false;

            if (rayCastResult1.Intersect)
            {
                if (Math.Abs(Vector3.Dot(rayCastResult1.CollisionNormal, Vector3.UnitX)) > 0.000001)
                {
                    slopeOnHitPoint1 = true;
                }
            }
            if (rayCastResult2.Intersect)
            {
                if (Math.Abs(Vector3.Dot(rayCastResult2.CollisionNormal, Vector3.UnitX)) > 0.000001)
                {
                    slopeOnHitPoint2 = true;
                }
            }

            //Conditons for slope collision:
            //1: Both rays hit on a slope
            //2: One ray hits a slope and the hit point where the slope is detected is higher than the other hitpoint
            bool condition1 = slopeOnHitPoint1 && slopeOnHitPoint2;
            bool condition2 = slopeOnHitPoint1 && rayCastResult1.HitPoint.Y > rayCastResult2.HitPoint.Y;
            bool condition3 = slopeOnHitPoint2 && rayCastResult2.HitPoint.Y > rayCastResult1.HitPoint.Y;


            if (condition1)
            {
                //Ray centerRay = new Ray(new Vector2((ray1.Points[0].X + ray2.Points[0].X)*0.5f,ray1.Points[0].Y), new Vector2((ray1.Points[1].X + ray2.Points[1].X) * 0.5f, ray1.Points[1].Y));
                if (Math.Abs(rayCastResult1.CollisionNormal.X) < Math.Abs(rayCastResult2.CollisionNormal.X))
                {
                    rayCastCollisionResult = rayCastResult1;
                }
                else
                {
                    rayCastCollisionResult = rayCastResult2;
                }
                //rayCastCollisionResult = rayCastResult1;
            }
            else if (condition2)
            {
                rayCastCollisionResult = rayCastResult1;
            }
            else if (condition3)
            {
                rayCastCollisionResult = rayCastResult2;
            }

            return(rayCastCollisionResult);
        }