private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0 && !OnGround)
        {
            MyAnimator.SetBool("falling", true);

            MyAnimator.SetBool("jump bool", false);
        }

        if (MyRigidbody.velocity.y == 0 && Time.time - jumpTime > 0.10)
        {
            MyAnimator.SetBool("jump bool", false);
        }

        if (!MyAnimator.GetBool("slide") && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (OnGround && Jump)
        {
            OnGround = false;

            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 2
0
    private void HandleMovement(float horizontal) // so we can use it here to change the value so defined earlier
    {
        if (MyRigidbody.velocity.y < 0)
        {
            myAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide && (OnGround || airControl))// &&  (KnockBackCount <= 0))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
            //moveVelocity = movementSpeed;
        }

        //else
        //{
        //  if (KnockFromRight)
        // MyRigidbody.velocity = new Vector2(-KnockBack, KnockBack);
        //if (!KnockFromRight)
        //   MyRigidbody.velocity = new Vector2(KnockBack, KnockBack);
        // KnockBackCount -= Time.deltaTime;
        //}

        //MyRigidbody.velocity = new Vector2(moveVelocity, MyRigidbody.velocity.y);

        if (Jump && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        myAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 3
0
    IEnumerator KnockBack()
    {
        MyRigidbody.AddForce(-transform.right * 300 * Time.deltaTime, ForceMode2D.Impulse);
        yield return(new WaitForSeconds(0.2f));

        MyRigidbody.velocity = Vector2.zero;
    }
Esempio n. 4
0
    private void HandleMovement(float horizontal, float vertical)
    {
        if (isRunning)
        {
            movementSpeed = 5f;
        }
        else
        {
            movementSpeed = 2f;
        }

        if (IsFalling)
        {
            gameObject.layer = 11;
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }
        if (Jump && OnGround && !TakeOff)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
            TakeOff = true;
        }
        if (OnLadder)
        {
            MyAnimator.speed     = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal);
            MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 5
0
    private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }

        if (!Attack && !Slide && !Crouch || (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (Jump && MyRigidbody.velocity.y == 0 && !Crouch)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        ////player boundaries on X axis
        //if (transform.position.x <= -4.3f)
        //{
        //    transform.position = new Vector2(-4.3f, transform.position.y);
        //}
        //else if (transform.position.x >= 27.75f)
        //{
        //    transform.position = new Vector2(27.75f, transform.position.y);
        //}

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 6
0
    public IEnumerator CloseDistance(Vector2 direction, float speed, float time)
    {
        MyRigidbody.AddForce(direction.normalized * speed * Time.deltaTime, ForceMode2D.Impulse);
        MyAnimator.enabled = false;
        yield return(new WaitForSeconds(time));

        MyAnimator.enabled   = true;
        MyRigidbody.velocity = Vector2.zero;
    }
    void OnCollisionEnter2D(Collision2D other)
    {
        float xDir = transform.position.x - other.transform.position.x;

        if (other.gameObject.tag == "Demons")
        {
            MyRigidbody.AddForce(new Vector2(knockBack * xDir, 0));
            StartCoroutine(TakeDamage());
        }
    }
Esempio n. 8
0
    private void HandleInput()
    {
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            MyAnimator.SetBool("crouch", true);
        }

        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            MyAnimator.SetBool("crouch", false);
        }

        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            MyAnimator.SetTrigger("jump");

            if (Jump && !OnGround)
            {
                if (Input.GetKeyDown(KeyCode.UpArrow))
                {
                    MyRigidbody.AddForce(new Vector2(0, doubleJumpForce));
                    MyAnimator.SetTrigger("jump");
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            MyAnimator.SetTrigger("slide");
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            MyAnimator.SetTrigger("attack");
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            MyAnimator.SetTrigger("throw");
            MyAnimator.SetBool("carry", false);
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            MyAnimator.SetTrigger("invoke");
            InvokeDoberman(0);
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene("Menu");
        }
    }
Esempio n. 9
0
    public void BtnJump()
    {
        // Used for button to make player jump

        if (OnGround && !IsDead)
        {
            MyAnimator.SetTrigger("jump");
            MyRigidbody.AddForce(new Vector2(0, jumpForce));


            Jump = true;
        }
    }
Esempio n. 10
0
 private void AttackCharge()
 {
     if (transform.localScale.x > 0)
     {
         Vector2 KnuckBackVelocity = new Vector2(12.5f, 0);
         MyRigidbody.AddForce(KnuckBackVelocity, ForceMode2D.Impulse);
     }
     else if (transform.localScale.x < 0)
     {
         Vector2 KnuckBackVelocity = new Vector2(-12.5f, 0);
         MyRigidbody.AddForce(KnuckBackVelocity, ForceMode2D.Impulse);
     }
 }
    private void handleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            myAnimator.SetBool("land", true);
        }

        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (Jump && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        myAnimator.SetFloat("speed", Mathf.Abs(horizontal));

        /*if (myRigidbody.velocity.y < 0) {
         *
         *      myAnimator.SetBool ("land", true);
         * }
         *
         * if (!myAnimator.GetBool("slide") && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsTag ("Attack") && (isGrounded || airControl)) {
         *
         *      //myRigidbody.velocity = Vector2.left; // x=-1, y=0
         *      myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y);
         *
         * }
         *
         * if (isGrounded && jump) {
         *
         *      isGrounded = false;
         *      myRigidbody.AddForce (new Vector2 (0, jumpForce));
         *      myAnimator.SetTrigger ("jump");
         * }
         *
         * if (slide && !this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide")) {
         *
         *      myAnimator.SetBool ("slide", true);
         * }
         *
         * else if (!this.myAnimator.GetCurrentAnimatorStateInfo (0).IsName ("Slide"))
         * {
         *
         *      myAnimator.SetBool ("slide", false);
         * }
         *
         * myAnimator.SetFloat ("speed", Mathf.Abs(horizontal));*/
    }
Esempio n. 12
0
    private void HandleMovement(float horizontal, float vertical)
    {
        if (Falling)
        {
            gameObject.layer = 10;
            MyAnimator.SetBool("land", true);
        }
        if (Jump && OnGround /*MyRigidbody.velocity.y == 0*/ && !OnLadder)
        {
            Debug.Log("-----------in side jumpmp OnGround--------------" + OnGround);
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
            //MyRigidbody.velocity =  (new Vector2(Mathf.Lerp(btnHorizontal, horizontal, Time.fixedDeltaTime * 2), jumpForce));
            //Player.Instance.transform.position += new Vector3(Player.Instance.horizontal == 1 ? 1 : -1, 0.5f, 0) * Time.fixedDeltaTime * 100;
            Jump = false;
        }
        if (!Attack && !Slide && (OnGround || airControl))
        {
            //Debug.Log("-----------in side run--------------" + Mathf.Lerp(btnHorizontal, horizontal, Time.fixedDeltaTime * 2));
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }
        //Debug.Log("-----------Jump--------------" + Jump/*+ "MyRigidbody.velocity.y == "+ MyRigidbody.velocity.y*/);
        //Debug.Log("-----------OnGround--------------" + OnGround);

        rd_velocity_x = MyRigidbody.velocity.x;
        rd_velocity_y = MyRigidbody.velocity.y;
        if (OnLadder)
        {
            MyAnimator.speed     = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal);
            MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
        Flip(horizontal);

        if (directionChanged)
        {
            directionChanged = false;
            touchThrow       = false;
        }
        else
        {
            if (touchThrow)
            {
                MyAnimator.SetTrigger("throw");
                touchThrow = false;
            }
        }
    }
Esempio n. 13
0
 // handles the movement of the player.
 private void HandleMovement(float horizontal)
 {
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);   // if the player is traveling down plays the land aniamtion.
     }
     if (!Attack && !Slide && (OnGround || airControl))
     {
         MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y); //moves the player.
     }
     if (Jump && MyRigidbody.velocity.y == 0)
     {
         MyRigidbody.AddForce(new Vector2(0, jumpForce));    // applies force so the player can jump.
     }
     MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));    // sets the animator to play the run animation.
 }
Esempio n. 14
0
 private void HandleMovement(float horizontal)
 {
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);
     }
     if (!Attack && !Slide && (OnGround || airControl))
     {
         MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
     }
     if (Jump && MyRigidbody.velocity.y == 0)
     {
         MyRigidbody.AddForce(new Vector2(0, jumpForce));
     }
     MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
 }
Esempio n. 15
0
 private void HandleMovement(float horizontal)
 {
     if (IsFalling && OnGround)
     {
         myAnimator.SetBool("land", true);
     }
     if (!Attack && (OnGround || airControl) && !knockBack)
     {
         MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
     }
     if ((Jump && (MyRigidbody.velocity.y == 0) && OnGround))
     {
         myAnimator.SetBool("land", false);
         MyRigidbody.AddForce(new Vector2(0, (MyRigidbody.velocity.y * 0) + jumpforce));
     }
     myAnimator.SetFloat("speed", Mathf.Abs(horizontal));
 }
Esempio n. 16
0
    public void Knockback(float KnockBackLength) // 넉백 거리
    {
        MyRigidbody.velocity = Vector2.zero;
        Vector2 KnuckBackVelocity_Right = new Vector2(KnockBackLength, MyRigidbody.velocity.y);
        Vector2 KnuckBackVelocity_Left  = new Vector2(-KnockBackLength, MyRigidbody.velocity.y);

        // 오른쪽
        if (transform.position.x > Player.position.x)
        {
            MyRigidbody.AddForce(KnuckBackVelocity_Right, ForceMode2D.Impulse);
        }
        // 왼쪽
        else
        {
            MyRigidbody.AddForce(KnuckBackVelocity_Left, ForceMode2D.Impulse);
        }
    }
Esempio n. 17
0
    private void FixedUpdate()
    {
        if (IsSpore)
        {
            IsSubdivided = true;


            if (!drifting)
            {
                MyConstantForce.enabled = false;
                MyConstantForce.force   = new Vector2();
                MyRigidbody.velocity    = (MyRigidbody.velocity * (1f - (Time.fixedDeltaTime * 2f)));
                if (MyRigidbody.velocity.magnitude < 0.1f)
                {
                    driftTime = Time.time;
                    drifting  = true;
                }
            }
            else
            {
                MyConstantForce.enabled = true;
                MyConstantForce.force   = Vector2.Lerp(MyConstantForce.force, (Random.insideUnitCircle.normalized * (WINDFORCEFACTOR * .2f * (1f + (Astronaut.AggressionLevelF * 1f)))), .5f) + ((new Vector2(0f, -1f) * .25f) * (1f - Astronaut.AggressionLevelF));
                if ((Time.time - driftTime) >= 15f)
                {
                    explode();
                }
            }
        }
        else
        {
            if (Live)
            {
                if (IsSubdivided)
                {
                    MyConstantForce.force = Vector2.Lerp(MyConstantForce.force, (Random.insideUnitCircle.normalized * WINDFORCEFACTOR), 1f);
                }
                Astronaut plr = Astronaut.TheAstronaut;
                Vector3   dif = (plr.transform.position - this.transform.position);
                if (dif.magnitude < 8f)
                {
                    //nerfed. They came from nowhere at full speed and you had no time to react.
                    MyRigidbody.AddForce(new Vector2(dif.x, dif.y).normalized *WINDFORCEFACTOR * 1f * Astronaut.AggressionLevelF);
                }
            }
        }
    }
Esempio n. 18
0
    //METHODS:

    private void HandleMovement(float horizontal) // The horizontal in the parenthesis gets its value from the float Horizontal = blah blah in the fixed update
    {
        if (!Attack && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }

        if (Jump && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(horizontal * movementSpeed, jumpForce));
        }
        MyAnimator.SetFloat("Speed", Mathf.Abs(horizontal));

        if (Crouch)
        {
            MyRigidbody.velocity = new Vector2(0, MyRigidbody.velocity.y);
        }
    }
Esempio n. 19
0
 // This is a function for player movement
 private void HandleMovement(float horizontal)
 {
     // If we are falling then start the landing animation
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);
     }
     // Horizontal movement
     if (!Attack && !Slide && (OnGround || airControl))
     {
         MyRigidbody.velocity = new Vector2(movementSpeed * horizontal, MyRigidbody.velocity.y);
     }
     if (Jump && MyRigidbody.velocity.y == 0)
     {
         MyRigidbody.AddForce(new Vector2(0, jumpForce));
     }
     // Set the speed in the Animator
     MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
 }
Esempio n. 20
0
    private void HandleMovement(float horizontal)
    {
        if (Jumping && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }
        if (IsFalling)
        {
            gameObject.layer = 10;
            MyAnimator.SetBool("Land", true);
        }
        if (!Attacking && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }


        MyAnimator.SetFloat("Speed", Mathf.Abs(horizontal));
    }
Esempio n. 21
0
    private void HandleMovement(float horizontal, float vertical)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide && OnGround)
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }
        if (Jump && MyRigidbody.velocity.y == 0 && !OnLadder)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }
        if (OnLadder)
        {
            MyAnimator.speed     = Mathf.Abs(vertical);
            MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 22
0
 protected void Jump(float JumpSpeed)
 {
     if (MyRigidbody.velocity.y != 0)
     {
         MyAnimator.SetBool("Jump", true);
         Jumping = true;
     }
     if (MyRigidbody.velocity.y < 0)
     {
         MyBoxCollider.enabled = true;
     }
     if ((RecognitionX >= -AttackRange && RecognitionX <= AttackRange) && RecognitionY <= -JumpRange && MyAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Walk"))
     {
         if ((transform.position.x >= JumpLimit[0] && transform.position.x <= JumpLimit[1]) || (transform.position.x >= JumpLimit[2] && transform.position.x <= JumpLimit[3]))
         {
             Jumping = true;
             MyRigidbody.velocity = Vector2.zero;
             Vector2 JumpVelocity = new Vector2(JumpSpeed, JumpForce);
             MyRigidbody.AddForce(JumpVelocity, ForceMode2D.Impulse);
         }
     }
 }
Esempio n. 23
0
    private void HandleMovement(float horizontal, float vertical)
    {
        if (Falling)
        {
            gameObject.layer = 10;
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && !Slide)
        {
            MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
        }
        if (Jump && MyRigidbody.velocity.y == 0 && !OnLadder)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }
        if (OnLadder)
        {
            MyAnimator.speed     = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal);
            MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 24
0
 // Движение персонажа
 private void HandleMovement(float Horizontal)
 {
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);
     }
     if (!Slide && (OnGround || airControl) && !IsDead)
     {
         MyRigidbody.velocity = new Vector2(Horizontal * MovementSpeed, MyRigidbody.velocity.y);
     }
     if (Jump && MyRigidbody.velocity.y == 0 && !IsDead)
     {
         MyRigidbody.AddForce(new Vector2(0, jumpForce));
     }
     if ((sideLeft == true && Horizontal < 0) || (sideRight == true && Horizontal > 0))
     {
         MyAnimator.SetFloat("speed", 0);
     }
     else
     {
         MyAnimator.SetFloat("speed", Mathf.Abs(Horizontal));
     }
 }
Esempio n. 25
0
    private void HandleMovement(float hInput)
    {
        // If we aren't moving up or down, we're on the ground.
        // (Not actually true but lolololYouTubeTutorials
        if (MyRigidbody.velocity.y < 0)
        {
            mAnimator.SetBool("land", true);
        }

        // If we aren't attacking, or sliding, and are either on the ground or in the air, we move.
        if (!Attack && !Slide && (OnGround || airControl))
        {
            MyRigidbody.velocity = new Vector2(hInput * movementSpeed, MyRigidbody.velocity.y);
        }

        // If we want to jump and we aren't currently falling, add jump force
        if (Jump && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        mAnimator.SetFloat("speed", Mathf.Abs(hInput));
    }
Esempio n. 26
0
    //handles the movement of player
    private void HandleMovement(float horizontal)
    {
        if (MyRigidbody.velocity.y < 0)
        {
            MyAnimator.SetBool("land", true);
        }
        if (!Attack && (OnGround || airControl))
        {
            if (IsRunning && Mathf.Abs(horizontal) > 0.01)

            /* checks if the running button is pressed or not and turns
             * the run animation only when both shift and direction keys are pressed*/
            {
                MyRigidbody.velocity = new Vector2(horizontal * WalkingSpeed * 2, MyRigidbody.velocity.y);
                MyAnimator.SetBool("run", true);
                MyAnimator.SetFloat("movementSpeed", WalkingSpeed * 2);

                /*speed is case sensitive and horizontal is made positive to compare
                 *              player goes right if speed is greater than 0.01 and left if less than 0.01
                 *              checks horizontal to see if the player pressed left or right button
                 *              speed is greater than 0.01 if the speed if player presses right and vice versa*/
            }
            else
            {
                MyRigidbody.velocity = new Vector2(horizontal * WalkingSpeed, MyRigidbody.velocity.y);
                MyAnimator.SetBool("run", false);
                MyAnimator.SetFloat("movementSpeed", WalkingSpeed);
            }
        }

        if (Jump && MyRigidbody.velocity.y == 0)
        {
            MyRigidbody.AddForce(new Vector2(0, jumpForce));
        }

        MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
    }
Esempio n. 27
0
 private void HandleMovement(float horizontal, float vertical)
 {
     //Otter falls
     if (MyRigidbody.velocity.y < 0)
     {
         MyAnimator.SetBool("land", true);
     }
     //Idling/running
     if (!Attack && (OnGround || airControl))
     {
         MyRigidbody.velocity = new Vector2(horizontal * movementSpeed, MyRigidbody.velocity.y);
     }
     //Jumping
     if (Jump && MyRigidbody.velocity.y == 0 && !OnLadder)
     {
         MyRigidbody.AddForce(new Vector2(0, jumpForce));
     }
     if (OnLadder)
     {
         MyAnimator.speed     = vertical != 0 ? Mathf.Abs(vertical) : Mathf.Abs(horizontal);
         MyRigidbody.velocity = new Vector2(horizontal * climbSpeed, vertical * climbSpeed);
     }
     MyAnimator.SetFloat("speed", Mathf.Abs(horizontal));
 }
Esempio n. 28
0
    void FixedUpdate()
    {
        Astronaut plr = Astronaut.TheAstronaut;

        if (Alive)
        {
            bool stateexpired = (Time.time >= (StateTime + StateDuration));

            switch (MyState)
            {
            case State.None: { break; }

            case State.FloatingBackAndForth:
            {
                MyRigidbody.bodyType = RigidbodyType2D.Dynamic;
                float sdif = (this.transform.position.x - StartPosition.x);
                if (Mathf.Abs(sdif) > 2f)
                {
                    float sig = Mathf.Sign(sdif);
                    GoLeftGoRight = (sig >= 0f);
                }
                MyRigidbody.AddForce(new Vector2(GoLeftGoRight ? -1f : 1f, 0f) * 3f);
                ChainsRetracting = true;

                //if (stateexpired)
                //{
                bool ch = false;

                if ((plr != null) && (plr.Alive) && (!Astronaut.TheAstronaut.Quelling))
                {
                    Vector3 dif = (plr.transform.position - this.transform.position);
                    if (dif.magnitude < 15f)
                    {
                        RaycastHit2D rh = Physics2D.Linecast(this.transform.position, plr.transform.position, LayerMask.GetMask(new string[] { "Geometry" }));

                        if (rh.distance <= 0f)
                        {
                            //The player is present. Invade their space
                            //Debug.Log("Approach");
                            //ParticleSystem s = ShootWindUpGlow;
                            setState(State.Invading, 2f);
                            ch = true;
                            //Debug.Log("Visible");
                        }
                        else
                        {
                            //Debug.Log("hiding...");
                        }
                    }
                }
                //if (!ch)
                // setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
                //}


                //if (MyRigidbody.velocity.x != 0f)
                //{
                //MySpriteRenderer.flipX = (Mathf.Sign(MyRigidbody.velocity.x) < 0f);
                //}

                break;
            }

            case State.Invading:
            {
                MyRigidbody.bodyType = RigidbodyType2D.Dynamic;
                ChainsRetracting     = true;
                if ((plr != null) && (plr.Alive) && (!Astronaut.TheAstronaut.Quelling))
                {
                    Vector3 dif = ((plr.transform.position + invadeoffset) - this.transform.position);
                    if (dif.magnitude < 10f)
                    {
                        RaycastHit2D rh = Physics2D.Linecast(this.transform.position, plr.transform.position, LayerMask.GetMask(new string[] { "Geometry" }));

                        if (rh.distance <= 0f)
                        {
                            //
                            //ParticleSystem s = ShootWindUpGlow;
                            if (dif.magnitude < 2f)
                            {
                                setState(State.Chaining, 2f);
                            }
                            else
                            {
                                MyRigidbody.AddForce(new Vector2(dif.normalized.x, dif.normalized.y) * (5f * (1f + (Astronaut.AggressionLevelF * 4f))));
                                MyRigidbody.drag = (.6f * (1f + (Astronaut.AggressionLevelF * 2f)));
                                //setState();
                            }


                            //Debug.Log("Visible");
                        }
                        else
                        {
                            setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
                        }
                    }
                    else
                    {
                        setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
                    }
                }

                if (stateexpired)
                {
                    Vector2 c = Random.insideUnitCircle;
                    invadeoffset = (new Vector3(c.x, c.y, 0f) * 2f);
                    StateTime    = Time.time;
                }


                break;
            }

            case State.Chaining:
            {
                MyRigidbody.bodyType = RigidbodyType2D.Static;
                //MyRigidbody.velocity = new Vector2();
                if ((plr != null) && (plr.Alive) && ((plr.transform.position - this.transform.position).magnitude < 4f) && (!Astronaut.TheAstronaut.Quelling) && (!isIncinerating()))
                {
                    ChainsRetracting = false;
                    if ((Time.time - StateTime) >= 5f)
                    {
                        ChainsRetracting = true;
                    }

                    if (ChainsRetracting)
                    {
                        if (isfullyretracted)
                        {
                            setState(State.Invading, 2f);
                        }
                    }
                }
                else
                {
                    if (stateexpired)
                    {
                        ChainsRetracting = true;
                    }
                    if (isfullyretracted)
                    {
                        setState(State.Invading, 2f);
                    }
                }

                //if (stateexpired)
                //{
                //  ChainsRetracting = true;
                //}



                break;
            }
            }



            if (isfullyretracted)
            {
                foreach (Chain c in Chains)
                {
                    c.MaxHealth = (50f * (1f + (2f * Astronaut.AggressionLevelF))); c.Health = c.MaxHealth; c.Alive = true;
                }
            }
            //MyRigidbody.velocity = new Vector2(movedir * movespeed, MyRigidbody.velocity.y);


            if (Alive)
            {
                Collider2D cha;
                float      maxdist       = 12f;
                float      expansionrate = 10f * Time.fixedDeltaTime + (1f + (3f * Astronaut.AggressionLevelF));
                bool       fr            = true;
                for (int i = 0; i < Chains.Length; i++)
                {
                    cha = Chains[i].MyCollider;
                    RaycastHit2D hit = Physics2D.Raycast(cha.transform.position, cha.transform.right, maxdist, LayerMask.GetMask(new string[] { "Geometry" }));
                    float        mx  = maxdist;
                    if (hit.distance <= 0)
                    {
                        //visible
                    }
                    else
                    {
                        //limited
                        mx = hit.distance;
                    }



                    float curr               = cha.transform.localScale.x;
                    bool  hitmax             = false;
                    bool  personalretracting = (!Chains[i].Alive);
                    float c = Mathf.Clamp(curr + ((ChainsRetracting || personalretracting) ? -expansionrate : expansionrate), 0f, maxdist);
                    if ((curr < mx) && (c >= mx) && (mx < maxdist))
                    {
                        hitmax = true;
                        curr   = mx;
                    }
                    else
                    {
                        curr = c;
                    }

                    if (hitmax)
                    {
                        if (impactSparks)
                        {
                            Am.am.oneshot(Am.am.M.ChainAttach, .3f);
                            impactSparks.transform.position = hit.point;
                            impactSparks.Emit(50);
                        }
                    }
                    cha.enabled = (curr > 0f);
                    if (curr <= 0f)
                    {
                    }
                    cha.transform.localScale = new Vector3(Mathf.Min(curr, mx), cha.transform.localScale.y, cha.transform.localScale.z);
                    if (curr > 0f)
                    {
                        fr = false;
                    }
                }

                isfullyretracted = fr;
            }
        }
        else
        {
            setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
        }
    }
    void FixedUpdate()
    {
        Astronaut plr = Astronaut.TheAstronaut;

        if (EtherealBehavior)
        {
            if (EtherealWillingToTeach)
            {
                MyCollider.enabled = true;
                if (LessonIndex == 0)
                {
                }
                else if (LessonIndex == 1)
                {
                    Vector3 dif = (plr.transform.position - this.transform.position);
                    if (Alive && !isStunned())
                    {
                        if (dif.x > 0f)
                        {
                            if ((Time.time - lastetherealshoottime) >= ETHEREALSHOOTINTERVAL)
                            {
                                IceSkullProjectile p = GameObject.Instantiate(SkullProjectile, this.transform.position, new Quaternion());
                                p.MyRigidbody.velocity = new Vector2(ETHEREALPROJECTILESPEED, 0f);
                                p.EtherealBehavior     = true;
                                lastetherealshoottime  = Time.time;
                            }
                        }
                    }
                }
            }
            else
            {
                MyCollider.enabled = false;
                if (!Frozen)
                {
                    MySpriteRenderer.flipX = (Mathf.Sign((plr.transform.position - this.transform.position).x) < 0f);
                }
            }
        }
        else
        if (Alive && !isStunned())
        {
            bool stateexpired = (Time.time >= (StateTime + StateDuration));

            switch (MyState)
            {
            case State.None: { break; }

            case State.FloatingBackAndForth: {
                float sdif = (this.transform.position.x - StartPosition.x);
                if (Mathf.Abs(sdif) > 2f)
                {
                    float sig = Mathf.Sign(sdif);
                    GoLeftGoRight = (sig >= 0f);
                }
                MyRigidbody.AddForce(new Vector2(GoLeftGoRight ? -1f : 1f, 0f) * 5f * (1f + (2f * Astronaut.AggressionLevelF)));


                if (stateexpired)
                {
                    bool ch = false;

                    if ((plr != null) && (plr.Alive) && (!Astronaut.TheAstronaut.Quelling))
                    {
                        Vector3 dif = (plr.transform.position - this.transform.position);
                        if (dif.magnitude < 10f)
                        {
                            RaycastHit2D rh = Physics2D.Linecast(this.transform.position, plr.transform.position, LayerMask.GetMask(new string[] { "Geometry" }));
                            Debug.Log(rh.distance);
                            if (rh.distance <= 0f)
                            {
                                Debug.Log("Take aim");
                                ParticleSystem s = ShootWindUpGlow;
                                setState(State.Firing, s.main.duration);
                                ch = true;
                                //Debug.Log("Visible");
                            }
                            else
                            {
                                Debug.Log("hiding...");
                            }
                        }
                    }
                    if (!ch)
                    {
                        setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
                    }
                }


                if (MyRigidbody.velocity.x != 0f)
                {
                    MySpriteRenderer.flipX = (Mathf.Sign(MyRigidbody.velocity.x) < 0f);
                }

                break;
            }

            case State.SwoopCharging:
            {
                break;
            }

            case State.Firing:
            {
                if ((plr != null) && (plr.Alive))
                {
                    Vector3 dif = (plr.transform.position - this.transform.position);
                    AimDirection = dif.normalized;
                }
                MySpriteRenderer.flipX = (Mathf.Sign(AimDirection.x) < 0f);
                if (stateexpired)
                {
                    ShootWindUpGlow.Play();



                    IceSkullProjectile p = GameObject.Instantiate(SkullProjectile, this.transform.position, new Quaternion());
                    float sp             = 5f * (1f + (2f * Astronaut.AggressionLevelF));
                    p.MyRigidbody.velocity = AimDirection * sp;

                    setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
                }
                else
                {
                    //MyRigidbody.bodyType = RigidbodyType2D.Kinematic;
                    MyRigidbody.velocity = new Vector2();
                }

                break;
            }
            }


            //MyRigidbody.velocity = new Vector2(movedir * movespeed, MyRigidbody.velocity.y);
        }
        else
        {
            setState(State.FloatingBackAndForth, .5f + (2f * Random.value));
        }
    }
Esempio n. 30
0
 public void AddForce(Vector2 force, ForceMode2D mode)
 {
     MyRigidbody.AddForce(force, mode);
 }