コード例 #1
0
    private void Backtrack(BoxRayCaster.RayTrigger trigger)
    {
        Vector2       rayDirection    = trigger.RayDirection;
        BoxCollider2D box             = boxRayCaster.boxCollider2D;
        Vector2       nowWorldCenter  = transform.TransformPoint(box.offset);
        Vector2       rayAbsDirection = new Vector2(Mathf.Abs(rayDirection.x), Mathf.Abs(rayDirection.y));
        Vector2       lastWorldCenter = nowWorldCenter - Vector2.Scale(Velocity, rayAbsDirection) * UpdateTime;
        float         step            = trigger.RayStep;
        float         length          = 100;
        ThreeRayCast  threeRayCast    = new ThreeRayCast(lastWorldCenter, rayDirection, step, length, backtrackLayer);
        RaycastHit2D? result          = threeRayCast.GetNearest();

        Debug.Assert(result.HasValue);
        Vector2 hitPoint   = result.Value.point;
        float   deltaValue = trigger.GetWorldDirectionValue(lastWorldCenter, hitPoint);

        //deltaValue += backtrackWidth;
        if (trigger.GetNeedVector2Value(Velocity) != 0)
        {
            //Vector2 nextWorldCenter = lastWorldCenter + deltaValue / trigger.GetNeedVector2Value(Velocity) * Velocity;
            Vector2 nextWorldCenter = lastWorldCenter + deltaValue * rayAbsDirection;
            Position += nextWorldCenter - nowWorldCenter;
            if (rayDirection.x == 0)
            {
                Velocity = new Vector2(Velocity.x, 0);
            }
            else
            {
                Velocity = new Vector2(0, Velocity.y);
            }
        }
    }
コード例 #2
0
 private void AddEnterAction(BoxRayCaster.RayTrigger trigger, System.Action <RaycastHit2D> action)
 {
     trigger.enterAction += action;
     destroyAction       += () => {
         trigger.enterAction -= action;
     };
 }
コード例 #3
0
 private void AddExitAction(BoxRayCaster.RayTrigger trigger, System.Action <Collider2D> action)
 {
     trigger.exitAction += action;
     destroyAction      += () => {
         trigger.exitAction -= action;
     };
 }
コード例 #4
0
 private void ProcessCollisionBacktrack(BoxRayCaster.RayTrigger trigger)
 {
     if (trigger.CheckCollision(backtrackLayer))
     {
         velocityBeforeBacktrack = Velocity;
         Backtrack(trigger);
     }
 }
コード例 #5
0
 public void DrawBoxTriggerStatus(string name, BoxRayCaster.RayTrigger trigger)
 {
     if (trigger != null)
     {
         EditorGUILayout.LabelField(name);
         EditorGUILayout.TextArea(trigger.CollisionStatus);
     }
 }