// Update is called once per frame
    void Update()
    {
        RaycastHit2D hit = spikeCollisionCaster.DetectCollisionRaycast(transform, false);

        if (GameCorePhysics2D.HasHit(hit))
        {
            spiked.Raise();
        }
    }
    void FixedUpdate()
    {
        RaycastHit2D hit = Item.CollisionDelegate.DetectCollisionRaycast(transform, false);

        if (GameCorePhysics2D.HasHit(hit))
        {
            Item.GetPickedUp(hit.transform);
            DestroyImmediate(gameObject);
        }
    }
        private bool RightClickOnNPC()
        {
            RaycastHit2D hit = CastRayFromMouseToWorld();

            if (!GameCorePhysics2D.HasHit(hit))
            {
                return(false);
            }

            IClickable clickable = hit.transform.GetComponent <IClickable>();

            if (clickable == null)
            {
                return(false);
            }

            clickable.OnRightClick();
            return(true);
        }
        private float SpeedToNotClipObstacle(
            Transform entityTransform,
            DetectCollisionDelegate collisionDelegate,
            bool flipDirectionOfDelegate,
            float velocityInCollisionDirection
            )
        {
            RaycastHit2D obstacleHit = collisionDelegate.DetectCollisionRaycast(
                entityTransform,
                flipDirectionOfDelegate
                );

            bool hasHit = GameCorePhysics2D.HasHit(obstacleHit);

            if (hasHit && obstacleHit.distance < Mathf.Abs(velocityInCollisionDirection))
            {
                return(obstacleHit.distance);
            }

            return(velocityInCollisionDirection);
        }
Ejemplo n.º 5
0
    public void Move(Transform entityTransform, float timeSpentMovingInDirection, bool flipDirectionNormalAlongAxis)
    {
        if (!DirectionNormalAlongAxis(directionNormalAlongAxis))
        {
            throw new Exception("TestingGeneralMoveEntityDelegate: direction vector is not normal and along an axis");
        }

        float   speed             = SpeedModulator.Output(timeSpentMovingInDirection);
        Vector2 movementDirection = flipDirectionNormalAlongAxis ? directionNormalAlongAxis * -1 : directionNormalAlongAxis;

        // Used to make sure the collisions in direction of movement are accurate (ex. won't move through obstacles).
        RaycastHit2D obstacleHit = obstacleDetector.DetectCollisionRaycast(entityTransform, flipDirectionNormalAlongAxis);

        if (GameCorePhysics2D.HasHit(obstacleHit) && obstacleHit.distance < speed)
        {
            entityTransform.position += (Vector3)movementDirection * obstacleHit.distance;
        }
        else
        {
            entityTransform.position += (Vector3)movementDirection * speed;
        }
    }
    // Update is called once per frame
    void Update()
    {
        RaycastHit2D hit = slashDetector.DetectCollisionRaycast(transform, false, maskName);

        if (GameCorePhysics2D.HasHit(hit))
        {
            if (!isHit)
            {
                Debug.Log("sliced");
                isHit = true;
                hits -= 1;
            }

            if (hits == 0)
            {
                EnableWaterfallDestroyBoss();
            }

            return;
        }

        isHit = false;
    }