예제 #1
0
 public LedgeInfo()
 {
     this.point     = Vector3.zero;
     this.direction = Vector3.zero;
     this.collider  = null;
     this.type      = LedgeType.Normal;
 }
예제 #2
0
 public Ledge builder(LedgeType type, Vector2 location)
 {
     factory = new SpriteFactory();
     if (type == LedgeType.ledgeLeftCurve)
     {
         state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftCurve);
     }
     if (type == LedgeType.ledgeLeftEnd)
     {
         state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftEnd);
     }
     if (type == LedgeType.ledgeMiddle)
     {
         state = new LedgeTileState(SpriteFactory.sprites.ledgeMiddle);
     }
     if (type == LedgeType.ledgeRightCurve)
     {
         state = new LedgeTileState(SpriteFactory.sprites.ledgeRightCurve);
     }
     if (type == LedgeType.ledgeRightEnd)
     {
         state = new LedgeTileState(SpriteFactory.sprites.ledgeRightEnd);
     }
     Ledge product = new Ledge(state, location);
     return product;
 }
예제 #3
0
        public Ledge builder(LedgeType type, Vector2 location)
        {
            factory = new SpriteFactory();
            if (type == LedgeType.ledgeLeftCurve)
            {
                state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftCurve);
            }
            if (type == LedgeType.ledgeLeftEnd)
            {
                state = new LedgeTileState(SpriteFactory.sprites.ledgeLeftEnd);
            }
            if (type == LedgeType.ledgeMiddle)
            {
                state = new LedgeTileState(SpriteFactory.sprites.ledgeMiddle);
            }
            if (type == LedgeType.ledgeRightCurve)
            {
                state = new LedgeTileState(SpriteFactory.sprites.ledgeRightCurve);
            }
            if (type == LedgeType.ledgeRightEnd)
            {
                state = new LedgeTileState(SpriteFactory.sprites.ledgeRightEnd);
            }
            Ledge product = new Ledge(state, location);

            return(product);
        }
예제 #4
0
 public LedgeInfo(LedgeType type, Vector3 point, Vector3 direction, Collider collider)
 {
     this.point     = point;
     this.direction = direction;
     this.collider  = collider;
     this.type      = type;
 }
 public LedgeDetails(bool p_found, LedgeType p_type, Vector3 p_location, Quaternion p_rotation, GameObject p_object)
 {
     ledgeFound     = p_found;
     ledgeType      = p_type;
     ledgeLocation  = p_location;
     targetRotation = p_rotation;
     ledgeObject    = p_object;
 }
예제 #6
0
    protected void MakeLedgeObj(Vector2 position, LedgeType type)
    {
        GameObject ledgeObj = Instantiate((GameObject)Resources.Load(LedgePrefabName), position, new Quaternion());
        U_Ledge    ledge    = ledgeObj.GetComponent <U_Ledge>();

        ledge.position         = position;
        ledge.type             = type;
        ledge.transform.parent = transform;
    }
예제 #7
0
 public LedgeInfo(LedgeType type, Vector3 point, Vector3 direction, Vector3 upNormal, Collider collider, float forwardAngle, float rightAngle)
 {
     this.point        = point;
     this.direction    = direction;
     this.upNormal     = upNormal;
     this.collider     = collider;
     this.type         = type;
     this.forwardAngle = forwardAngle;
     this.rightAngle   = rightAngle;
 }
예제 #8
0
    // Use this for initialization
    void Start()
    {
        blockBounds = block.GetComponent <Renderer>().bounds;
        //Debug.Log("Extents:"+blockBounds.extents);
        //Debug.Log("Size:" + blockBounds.size);
        //Debug.Log("Centre:" + blockBounds.center);

        PositionBlock();

        prevLedgeType = ledgeType;
    }
    LedgeDetails CheckFit(Transform p_referenceObject,
                          Vector3 p_referenceObjectSize,
                          RaycastHit p_hit,
                          Vector3 p_faceDirection,
                          LedgeType p_ledgeType,
                          float p_precisionCorrection = 0.0f
                          )
    {
        LedgeDetails ledgeDetail = new LedgeDetails();

        RaycastHit[] intersectingColliders;
        Collider[]   targetPositionCollisions = new Collider[0];
        Vector3      castCapsuleP1;
        Vector3      castCapsuleP2;

        Quaternion yRotation;
        Quaternion xzRotation;



        ledgeDetail.ledgeFound = false;

        //We are going to place the Hand/Body reference at the hit point
        //in the desired direction, and see if the hand/body will fit in the identified ledge
        p_referenceObject.rotation = Quaternion.identity;
        p_referenceObject.position = p_hit.point;

        //Forward will be rotated around Y, to face the expected direction
        //i.e., Rotate the reference object around Y to face the direction
        yRotation = Quaternion.FromToRotation(p_referenceObject.forward, p_faceDirection);
        p_referenceObject.rotation *= yRotation;

        //</TBD>Temporary comment
        //Debug.DrawRay(p_hit.point,
        //                p_faceDirection,
        //                    Color.yellow,
        //                        p_hit.normal.magnitude);
        //<TBD/>Temporary comment

        //Rotate the reference object around XZ to be aligned with the ledge/normal
        xzRotation = Quaternion.FromToRotation(p_referenceObject.up, p_hit.normal);
        p_referenceObject.rotation = xzRotation * p_referenceObject.rotation;

        //Move the aligned reference object slightly above the ledge
        //Adding 0.055f to make sure the box cast starts slightly above the identified ledge surface
        //This is to avoid collision of boxcast with the ledge itself
        p_referenceObject.transform.Translate(0, 0.055f + p_referenceObjectSize.y / 2, p_referenceObjectSize.z / 2);

        //Check if there is enough room for hand/player
        //If the below box cast (size of the hand/body) does not collide with anything, there is enough room for hand/player
        intersectingColliders = Physics.BoxCastAll(
            p_referenceObject.transform.position,
            new Vector3(p_referenceObjectSize.x / 2, p_referenceObjectSize.y / 2, p_referenceObjectSize.z / 2),
            p_referenceObject.transform.up,
            p_referenceObject.rotation,
            0.0f,
            movementBlockerLayers
            );
        handGizmo.transform.position = p_referenceObject.position;
        handGizmo.transform.rotation = p_referenceObject.rotation;
        if (p_ledgeType == LedgeType.Ledge)
        {
        }
        else
        {
            bodyGizmo.transform.position = p_referenceObject.position;
            bodyGizmo.transform.rotation = p_referenceObject.rotation;
        }

        if (intersectingColliders.Length == 0)
        {
            ledgeDetail.ledgeLocation  = p_hit.point;                                               //A ledge is found at this point
            ledgeDetail.targetRotation = Quaternion.identity;
            ledgeDetail.targetRotation = Quaternion.AngleAxis(yRotation.eulerAngles.y, Vector3.up); //Apply just the Y rotation to face player to the wall

            //Identify the capsule end points
            //i.e., if the player is going to be hanging from the ledge
            //will the player be colliding with anything
            castCapsuleP1 = (ledgeDetail.ledgeLocation - ledgeDetail.targetRotation * (handTarget.transform.localPosition + new Vector3(0, 0, p_precisionCorrection))) +
                            controller.center +
                            controller.transform.up *
                            -((controller.height * 0.5f) - controller.radius);
            castCapsuleP2 = castCapsuleP1 + controller.transform.up * (controller.height - (2 * controller.radius));

            capsuleCastPoint1 = castCapsuleP1;
            capsuleCastPoint2 = castCapsuleP2;

            if (!Physics.CheckCapsule(castCapsuleP1, castCapsuleP2, controller.radius, movementBlockerLayers))
            {
                ledgeDetail.ledgeFound = true; //A ledge has been found
                ledgeDetail.ledgeType  = p_ledgeType;
                return(ledgeDetail);
            }
        }
        else
        {
        }

        return(new LedgeDetails());
    }