// Update is called once per frame
 void Update()
 {
     movingEntity.SetDirection(direction);
     if (movementRate > 0 && Time.fixedTime - timeSinceLastMove > 60 / movementRate + randTime)
     {
         randTime = Random.Range(-20 / movementRate, 20 / movementRate);
         goingTo  = GetComponentInParent <SpawnZone>().GeneratePosition();
         SpawnZone a = GetComponentInParent <SpawnZone>();
         if (a == null)
         {
             Debug.Log("probl");
         }
         direction         = (goingTo - transform.parent.position).normalized;
         timeSinceLastMove = Time.fixedTime;
     }
     if (Vector3.Dot((goingTo - transform.parent.position), direction) <= 0)
     {
         direction = Vector3.zero;
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        if (playerCollider == null)
        {
            playerCollider = GameHandler.instance.player.GetComponentInParent <Collider2D>();
        }
        FightingUpdate();
        Vector2 toPlayer = (Vector2)(playerTransform.position - transform.position);

        if (toPlayer.magnitude < VisionRange)
        {
            movingEntity.SetDirection(toPlayer.normalized);
        }
        if (!IsFlickering() && myCollider.IsTouching(attackCollider))
        {
            HitSelf(playerBehavior.GetAttackDirection());
        }
        else if (IsCanAttack() && myCollider.IsTouching(playerCollider))
        {
            HitPlayer(toPlayer);
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (!GameHandler.instance.isPhysicsPaused)
        {
            direction = new Vector2(0, 0);
            if (Input.GetButton("Up"))
            {
                direction.y += 1;
            }
            if (Input.GetButton("Down"))
            {
                direction.y -= 1;
            }
            if (Input.GetButton("Right"))
            {
                direction.x += 1;
            }
            if (Input.GetButton("Left"))
            {
                direction.x -= 1;
            }
            //GUIHandler.instance.debugText.text = direction.ToString();

            if (direction.magnitude > 1)
            {
                timeSinceDiagonal = Time.fixedTime;
                facingDirection   = direction;
            }
            else if (direction.magnitude == 1 && Time.fixedTime - timeSinceDiagonal > switchTime)
            {
                facingDirection = direction;
            }

            movingEntity.SetDirection(direction);
        }
    }