Пример #1
0
    private void Awake()    // all initialisation should be performed in awake because FixedUpdate may be called before start when this is instantiated at runtime
    {
        rigidBody = GetComponentInParent <Rigidbody>();

        UpdateTransforms();
        prevPosition = attachmentPoint;

        inertia = mass * (radius * radius) / 2;
        slipForce.postWrapMode = WrapMode.ClampForever;
        raycastBitmask         = CollisionMatrixLayerMasks.ForLayer(gameObject.layer);
    }
Пример #2
0
    public static Collider2D ComputeHorizontalRaycast(Vector2 origin, Collider2D refCollider, int objectLayer, bool drawDebug, float debugDuration, Color color)
    {
        origin.y -= refCollider.bounds.size.y * 0.55f - refCollider.offset.y;
        origin.x -= refCollider.bounds.size.x * 0.3f;
        float distance = refCollider.bounds.size.x * 0.8f;

        int layer = CollisionMatrixLayerMasks.MaskForLayer(objectLayer);

        if (drawDebug)
        {
            Debug.DrawRay(origin, Vector3.right * distance, color, debugDuration);
        }

        RaycastHit2D hitInfos = Physics2DUtility.RaycastAllWithEffector(origin, Vector2.right, distance, layer, drawDebug);

        return(hitInfos ? hitInfos.collider : null);
    }
Пример #3
0
    public static Collider2D ComputeVerticalRayWithEffector(Vector2 origin, Collider2D refCollider, float forward, int objectLayer, bool drawDebug = false, float debugDuration = 0f)
    {
        float distance = refCollider.bounds.size.y * 0.75f;

        origin.x += forward * refCollider.bounds.size.x * 0.55f + (forward * 0.1f);
        origin.y += refCollider.bounds.size.y * 0.4f + refCollider.offset.y;

        int layer = CollisionMatrixLayerMasks.MaskForLayer(objectLayer);

        if (drawDebug)
        {
            Debug.DrawRay(origin, Vector3.down * distance, Color.red, debugDuration);
        }

        RaycastHit2D hitInfos = Physics2DUtility.RaycastAllWithEffector(origin, Vector2.down, distance, layer, drawDebug);

        return(hitInfos ? hitInfos.collider : null);
    }