Exemple #1
0
    void FixedUpdate()
    {
        if (!IsInitialized)
        {
            return;
        }
        if (!target || !transform)
        {
            UnityEngine.AddressableAssets.Addressables.ReleaseInstance(this.gameObject);
            IsHit = true;
        }
        if (IsHit)
        {
            return;
        }
        Vector3 a = 2f * ((target.position - transform.position) - (rigidbody.velocity * HitTime)) / (HitTime * HitTime);

        rigidbody?.AddForce(a, ForceMode.Acceleration);
        if (HitTime > 0)
        {
            HitTime -= Time.deltaTime;
        }
        if (HitTime <= 0)
        {
            HitTime = 0.01f;
        }
    }
Exemple #2
0
    void ApplyDamage(GameObject collidedObject)
    {
        if (collidedObject.tag == collisionObjectiveTag)
        {
            collidedObjectHealth  = collidedObject.GetComponent <HealthAction>();
            collidedObjectRB      = collidedObject.GetComponent <Rigidbody>();
            collidedObjectNavMesh = collidedObject.GetComponent <NavMeshAgent>();

            collidedObjectHealth?.ChangeHealth(-this.damage);

            if (collidedObjectNavMesh != null && collidedObjectNavMesh.enabled)
            {
                collidedObjectNavMesh.enabled = false;
                collidedObjectRB.isKinematic  = false;
                Invoke("ReEnableCollidedObjectNavMesh", 0.25f);
            }


            collidedObjectRB?.AddForce(this.gameObject.transform.forward * knockback, ForceMode.Impulse);
        }

        if (this.selfDestroyOnCollision)
        {
            Destroy(this.gameObject);
        }
    }
 void ProcessButtonPress(object data)
 {
     if (data.ToString() == EventId.KeyPad_1_Pressed)
     {
         m_Mode = Mode.Spawn_Green_Dominos;
     }
     else if (data.ToString() == EventId.KeyPad_2_Pressed)
     {
         m_Mode = Mode.Spawn_Red_Dominos;
     }
     else if (data.ToString() == EventId.KeyPad_3_Pressed)
     {
         m_Mode = Mode.Edit_Environment;
     }
     else if (data.ToString() == EventId.KeyPad_4_Pressed)
     {
         m_Mode = Mode.Spawn_Ball;
     }
     else if (data.ToString() == EventId.Spacebar_Pressed)
     {
         if (m_CameraType == CameraType.FlyBy)
         {
             GameObject ballObject = GameObject.Instantiate(m_Ball);
             ballObject.transform.position = GameCamera.transform.position + 1.5f * GameCamera.transform.forward;
             Rigidbody rigidbody = ballObject.GetComponent <Rigidbody>();
             rigidbody?.AddForce(GameCamera.transform.forward * 150, ForceMode.Force);
         }
     }
 }
Exemple #4
0
    //GameObject currentProjectile;

    public void Shoot()
    {
        currentTarget?.AddForce(-hit.normal * force, ForceMode.Impulse);
        Target target = currentTarget?.GetComponent <Target>();

        target?.GetDamage(damage);
    }
Exemple #5
0
    public override void OnAttack(GameObject attacker, GameObject defender, AttackDefinition attackDefinition, Attack attack)
    {
        Rigidbody rb       = defender.GetComponent <Rigidbody>();
        Vector3   forceDir = (defender.transform.position - attacker.transform.position).normalized;

        forceDir.y += 0.5f;
        rb?.AddForce(forceDir * forceAmount);
    }
 // Update is called once per frame
 void Update()
 {
     if (_input != null && Math.Abs(_input.Value) > 0.001f)
     {
         if (_useRelativeForce)
         {
             _target?.AddRelativeForce(_direction * _input * Time.deltaTime, _mode);
         }
         else
         {
             _target?.AddForce(_direction * _input, _mode);
         }
     }
 }
    protected void RemovePart(GameObject part)
    {
        if (part == null)
        {
            return;
        }
        Vector3 forceDirection = (part.transform.position - transform.position).normalized;

        if (_partDetachSFX != null && _partDetachSFX.isPlaying == false)
        {
            _partDetachSFX.Play();
        }
        part.transform.parent = null;
        part.GetComponent <Collider>().enabled = true;
        Rigidbody rigidbody = (Rigidbody)part.AddComponent(typeof(Rigidbody));

        rigidbody?.AddForce(forceDirection * _detachForce, ForceMode.Impulse);
    }
 private void StartCrouch()
 {
     transform.localScale = crouchScale;
     transform.position   = new Vector3(transform.position.x, transform.position.y - 0.5f, transform.position.z);
     if (rb.velocity.magnitude > 0.5f)
     {
         if (grounded)
         {
             rb.AddForce(orientation.transform.forward * slideForce);
         }
     }
 }
Exemple #9
0
    IEnumerator OpenDoor()
    {
        //transform of doorPanels
        var       leftDoor  = transform.parent.GetChild(0);
        var       rightDoor = transform.parent.GetChild(1);
        Rigidbody rb_Left   = leftDoor.GetComponent <Rigidbody>();
        Rigidbody rb_Right  = rightDoor.GetComponent <Rigidbody>();

        print("start CoroutineDoor");


        if (!isOpenForward)
        {
            // add some forward force
            rb_Left.AddForce(leftDoor.forward * 50);
            rb_Right.AddForce(rightDoor.forward * 50);
            print("naar voren");

            // forward animation ends after 2 seconds
            yield return(new WaitForSeconds(2.0f));

            isOpenForward = !isOpenForward;

            // slow down the object
            rb_Left.drag  = 500;
            rb_Right.drag = 500;

            // make sure the object will be able to move again when closing the door
            rb_Left.drag  = 1;
            rb_Right.drag = 1;

            // done
            yield return(null);
        }

        if (!isOpenSideways)
        {
            // add sideway force to "open" the door
            rb_Left.AddForce(leftDoor.right * 120);
            rb_Right.AddForce(-rightDoor.right * 120);
            print("naar opzij");

            yield return(new WaitForSeconds(2.5f));

            isOpenSideways = !isOpenSideways;
            rb_Left.drag   = 500;
            rb_Right.drag  = 500;

            rb_Left.drag  = 1;
            rb_Right.drag = 1;

            // done
            yield return(null);
        }



        // door is fully opened
        if (isOpenForward && isOpenSideways)
        {
            // enemy has to move trough the door
            StartCoroutine(MoveInitialEnemy());
            yield return(new WaitForSeconds(2.0f));


            // start closing door
            StartCoroutine(CloseDoor(rb_Left, rb_Right));
            isOpenForward  = !isOpenForward;
            isOpenSideways = !isOpenSideways;
            yield return(null);
        }
        yield return(null);
    }
Exemple #10
0
    // Update is called once per frame
    void Update()
    {
        Vector3 playerPos = target.transform.position; //プレイヤーの位置

        direction = playerPos - transform.position;    //方向
        direction = direction.normalized;              //単位化(距離要素を取り除く)

        anim.SetFloat("x", rigid.velocity.x);
        anim.SetFloat("z", rigid.velocity.z);
        float distanse = Vector3.Distance(playerPos, transform.position);         //相手との距離


        if (distanse <= 0.8f)
        {
            if (dir == direction)
            {
                isMove = false;
                DashEnd();
                rigid.velocity = Vector3.zero;
                //StopCoroutine (MidAction());
                StopCoroutine(FarAction());
                //isChase = false;
            }
        }
        if (distanse <= 1)
        {
            isChase = true;
            cState  = CombatType.near;
            StopCoroutine(MidAction());
        }
        else if (distanse <= 5)
        {
            cState = CombatType.mid;
        }
        else
        {
            cState = CombatType.far;
        }

        //combat
        switch (cState)
        {
        case CombatType.near:

            StartCoroutine(NearAction());
            break;

        case CombatType.mid:
            StartCoroutine(MidAction());
            break;

        case CombatType.far:
            StartCoroutine(FarAction());

            FollwTarget(direction);
            break;
        }


        //FollwTarget ();

        if (isMove)
        {
            FollwTarget(dir);
        }

        LookAtTarget();



        if (anim.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
        {
            canMove              = false;
            canCombo             = true;
            anim.applyRootMotion = true;
        }
        else
        {
            canCombo             = false;
            anim.applyRootMotion = false;
        }

        if (anim.GetCurrentAnimatorStateInfo(0).IsTag("Move"))
        {
            canCombo = false;
            canMove  = true;
            anim.ResetTrigger("Combo");
        }

        if (anim.GetCurrentAnimatorStateInfo(0).IsName("DashAttack"))
        {
            rigid.AddForce(transform.forward * 40);
        }


        //移動管理
        if (anim.GetCurrentAnimatorStateInfo(0).IsTag("Move") || anim.GetCurrentAnimatorStateInfo(0).IsName("Dash"))
        {
            canMove = true;

            isRotate = true;
        }
        else
        {
            canMove  = false;
            isRotate = false;
        }

        if (!canMove)
        {
            rigid.velocity = Vector3.zero;
        }


        if (anim.GetCurrentAnimatorStateInfo(0).IsName("Dash"))
        {
            //Debug.Log (rigid.velocity);

            if (rigid.velocity != Vector3.zero)
            {
                efect = true;
            }
            else
            {
                efect = false;
            }

            //	anim.SetFloat ("ComboAttack",0);
        }
        else
        {
            efect = false;
            //ps.Stop ();
        }
        if (efect)
        {
            ps.Play();
        }
        else
        {
            ps.Stop();
        }
    }
Exemple #11
0
 // Use this for initialization
 void Start()
 {
     rb = GetComponent <Rigidbody> ();
     rb.AddForce(new Vector3(0.0f, 0.8f, 1.0f) * speed);
 }
 private void FixedUpdate()
 {
     _rigidBody.AddForce(magnusConstant * Time.deltaTime * Vector3.Cross(_rigidBody.angularVelocity,
                                                                         _rigidBody.velocity));
 }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(1) && m_Mode == Mode.Edit_Environment)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out m_HitObject))
            {
                if (m_HitObject.transform.gameObject.CompareTag("Ground") && m_HitObject.transform.position.y > m_CellSize * 0.5f)
                {
                    GameObject.Destroy(m_HitObject.transform.gameObject);
                }
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out m_HitObject))
            {
                if (m_HitObject.transform.gameObject.CompareTag("Ground"))
                {
                    Vector3 position = m_HitObject.transform.position;

                    if (m_Mode == Mode.Edit_Environment)
                    {
                        CubeBehavior behavior = m_HitObject.transform.parent.gameObject.GetComponent <CubeBehavior>();

                        if (!Physics.Raycast(new Ray(position, Vector3.up), out m_HitObject))
                        {
                            position.y += m_CellSize * 0.5f;
                            GameObject temp = GameObject.Instantiate(m_Cell);
                            temp.transform.parent   = GridRoot.transform;
                            temp.transform.position = position;

                            if (behavior.Type == CubeType.White)
                            {
                                temp.GetComponent <CubeBehavior>().Type           = CubeType.Black;
                                temp.GetComponentInChildren <Renderer>().material = m_Black;
                            }
                            else
                            {
                                //No need to change material as default material is white
                                temp.GetComponent <CubeBehavior>().Type = CubeType.White;
                            }
                        }
                    }
                    else if (m_Mode == Mode.Spawn_Green_Dominos)
                    {
                        position.y += m_CellSize * 0.6f;//Little bit of drop effect . 0.5 will make it spawn exactly on ground . 0.6 bit above the ground
                        GameObject temp = GameObject.Instantiate(m_GreenDomino);
                        temp.transform.parent   = DominosRoot.transform;
                        temp.transform.position = position;
                        temp.transform.right    = GameCamera.transform.right;
                    }
                    else if (m_Mode == Mode.Spawn_Red_Dominos)
                    {
                        position.y += m_CellSize * 0.6f;
                        GameObject temp = GameObject.Instantiate(m_RedDomino);
                        temp.transform.parent   = DominosRoot.transform;
                        temp.transform.position = position;
                        temp.transform.right    = GameCamera.transform.right;
                    }
                    else if (m_Mode == Mode.Spawn_Ball)
                    {
                        position.y += m_CellSize * 1.5f;
                        GameObject ballObject = GameObject.Instantiate(m_Ball);
                        ballObject.transform.position = position;
                        Rigidbody rigidbody = ballObject.GetComponent <Rigidbody>();
                        rigidbody?.AddForce(GameCamera.transform.right * 170, ForceMode.Force);
                    }
                }
            }
        }
    }
    // public GameObject Ammo;



    void Update()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            Vector3 force = new Vector3(0, jumpForce, 0);

            rb.AddForce(force);
            Debug.Log("Got Key Down");
        }
        if (Input.GetKey(KeyCode.D))
        {
            Vector3 keyd = new Vector3(moveForce, 0, 0);

            rb.AddForce(keyd);
            Debug.Log("Got Key D");

            hopefully(true);
        }

        if (Input.GetKey(KeyCode.A))
        {
            Vector3 keya = new Vector3(-moveForce, 0, 0);

            rb.AddForce(keya);
            Debug.Log("Got Key A");

            hopefully(false);
        }


        if (Input.GetKeyDown(ShootKey))
        {
            shoot();
        }

        if (Input.GetKeyDown(negativeShootKey))
        {
            Rigidbody clone;

            Vector3 fix = new Vector3(-0.5f, 0.5f, 0f);
            clone          = Instantiate(rbAmmo, transform.position + fix, transform.rotation);
            clone.velocity = transform.TransformDirection(-AmmoForce, 0f, 0f);

            Vector3 keyr = new Vector3(-AmmoForce, 0, 0);
            rbAmmo.AddForce(keyr);
        }



        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Vector3 force2 = new Vector3(0, jumpForce, 0);

            rb2.AddForce(force2);
            Debug.Log("Got Key Down");
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            Vector3 keyright = new Vector3(moveForce, 0, 0);

            rb2.AddForce(keyright);
            Debug.Log("Got Key D");
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            Vector3 keyleft = new Vector3(-moveForce, 0, 0);

            rb2.AddForce(keyleft);
            Debug.Log("Got Key A");
        }
        // BoxCollider pick = PickUp.GetComponent<BoxCollider>();
    }
Exemple #15
0
 /// <summary>
 /// this function adds force to the rigidbody making the object this class is on move in it's set direction.
 /// </summary>
 private void MoveProjectile()
 {
     _rb?.AddForce(transform.forward * _velocity, ForceMode.Impulse);
 }
Exemple #16
0
    void Update()
    {
        float move = Input.GetAxis("Horizontal");

        /*
         * if (player.velocity.y<maxFallSpeed)
         * {
         *      player.velocity = new Vector3(move*speed + fanSpeed, maxFallSpeed, 0f);
         * }
         * else
         * {
         *      player.velocity = new Vector3(move*speed + fanSpeed, player.velocity.y, 0f);
         * }
         */

        if (movePlatformLeft && move < 0)
        {
            player.velocity = new Vector3(-1f, player.velocity.y, 0f);
        }
        else if (movePlatformRight && move > 0)
        {
            player.velocity = new Vector3(1f, player.velocity.y, 0f);
        }
        else
        {
            player.velocity = new Vector3(move * PlayerSettings.Instance.Speed + fanSpeed, player.velocity.y, 0f);
        }

        if (jump && player.velocity.y <= 0)
        {
            jump = false;
        }

        if (ground && Mathf.Abs(player.velocity.y) < 0.01f)
        {
            if (timeForJump > 0)
            {
                timeForJump--;
            }
        }

        if ((Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) &&
            jump == false && ground && timeForJump <= 0)
        {
            player.velocity = new Vector3(player.velocity.x, 0f, 0f);
            player.AddForce(new Vector3(0f, PlayerSettings.Instance.JumpForce, 0f));
            jump        = true;
            ground      = false;
            timeForJump = 8;
        }

        if (Input.GetKeyDown(KeyCode.Space) &&
            PlayerSettings.Instance.CurPressureState != PlayerSettings.PressureState.High)
        {
            human = Instantiate(humanPref, new Vector3(playerPos.position.x + 1.05f,
                                                       playerPos.position.y,
                                                       playerPos.position.z - 0.01f), Quaternion.identity) as GameObject;
            player.isKinematic = true;
            playerPos.position = new Vector3(playerPos.position.x, playerPos.position.y, playerPos.position.z + 2f);
            script.enabled     = false;
            cameraScript.ChangeTarget();
        }
    }
 public void Release(Vector3 forceVelocity)
 {
     Release();
     _rigidbody.AddForce(forceVelocity, ForceMode.Impulse);
 }
        // 以下、メイン処理.リジッドボディと絡めるので、FixedUpdate内で処理を行う.
        void FixedUpdate()
        {
            if (!isMine)
            {
                return;
            }

            float h = Input.GetAxis("Horizontal");                  // 入力デバイスの水平軸をhで定義
            float v = Input.GetAxis("Vertical");                    // 入力デバイスの垂直軸をvで定義

            anim.SetFloat("Speed", v);                              // Animator側で設定している"Speed"パラメタにvを渡す
            anim.SetFloat("Direction", h);                          // Animator側で設定している"Direction"パラメタにhを渡す
            anim.speed       = animSpeed;                           // Animatorのモーション再生速度に animSpeedを設定する
            currentBaseState = anim.GetCurrentAnimatorStateInfo(0); // 参照用のステート変数にBase Layer (0)の現在のステートを設定する
            rb.useGravity    = true;                                //ジャンプ中に重力を切るので、それ以外は重力の影響を受けるようにする



            // 以下、キャラクターの移動処理
            velocity = new Vector3(0, 0, v);        // 上下のキー入力からZ軸方向の移動量を取得
                                                    // キャラクターのローカル空間での方向に変換
            velocity = transform.TransformDirection(velocity);
            //以下のvの閾値は、Mecanim側のトランジションと一緒に調整する
            if (v > 0.1)
            {
                velocity *= forwardSpeed;       // 移動速度を掛ける
            }
            else if (v < -0.1)
            {
                velocity *= backwardSpeed;  // 移動速度を掛ける
            }

            if (Input.GetButtonDown("Jump"))
            {   // スペースキーを入力したら
                //アニメーションのステートがLocomotionの最中のみジャンプできる
                if (currentBaseState.nameHash == locoState)
                {
                    //ステート遷移中でなかったらジャンプできる
                    if (!anim.IsInTransition(0))
                    {
                        rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange);
                        anim.SetBool("Jump", true);     // Animatorにジャンプに切り替えるフラグを送る
                    }
                }
            }



            // 上下のキー入力でキャラクターを移動させる
            transform.localPosition += velocity * Time.fixedDeltaTime;

            // 左右のキー入力でキャラクタをY軸で旋回させる
            transform.Rotate(0, h * rotateSpeed, 0);



            // 以下、Animatorの各ステート中での処理
            // Locomotion中
            // 現在のベースレイヤーがlocoStateの時
            if (currentBaseState.nameHash == locoState)
            {
                //カーブでコライダ調整をしている時は、念のためにリセットする
                if (useCurves)
                {
                    resetCollider();
                }
            }
            // JUMP中の処理
            // 現在のベースレイヤーがjumpStateの時
            else if (currentBaseState.nameHash == jumpState)
            {
                cameraObject.SendMessage("setCameraPositionJumpView");  // ジャンプ中のカメラに変更
                                                                        // ステートがトランジション中でない場合
                if (!anim.IsInTransition(0))
                {
                    // 以下、カーブ調整をする場合の処理
                    if (useCurves)
                    {
                        // 以下JUMP00アニメーションについているカーブJumpHeightとGravityControl
                        // JumpHeight:JUMP00でのジャンプの高さ(0〜1)
                        // GravityControl:1⇒ジャンプ中(重力無効)、0⇒重力有効
                        float jumpHeight     = anim.GetFloat("JumpHeight");
                        float gravityControl = anim.GetFloat("GravityControl");
                        if (gravityControl > 0)
                        {
                            rb.useGravity = false;  //ジャンプ中の重力の影響を切る
                        }
                        // レイキャストをキャラクターのセンターから落とす
                        Ray        ray     = new Ray(transform.position + Vector3.up, -Vector3.up);
                        RaycastHit hitInfo = new RaycastHit();
                        // 高さが useCurvesHeight 以上ある時のみ、コライダーの高さと中心をJUMP00アニメーションについているカーブで調整する
                        if (Physics.Raycast(ray, out hitInfo))
                        {
                            if (hitInfo.distance > useCurvesHeight)
                            {
                                col.height = orgColHight - jumpHeight;      // 調整されたコライダーの高さ
                                float adjCenterY = orgVectColCenter.y + jumpHeight;
                                col.center = new Vector3(0, adjCenterY, 0); // 調整されたコライダーのセンター
                            }
                            else
                            {
                                // 閾値よりも低い時には初期値に戻す(念のため)
                                resetCollider();
                            }
                        }
                    }
                    // Jump bool値をリセットする(ループしないようにする)
                    anim.SetBool("Jump", false);
                }
            }
            // IDLE中の処理
            // 現在のベースレイヤーがidleStateの時
            else if (currentBaseState.nameHash == idleState)
            {
                //カーブでコライダ調整をしている時は、念のためにリセットする
                if (useCurves)
                {
                    resetCollider();
                }
                // スペースキーを入力したらRest状態になる
                if (Input.GetButtonDown("Jump"))
                {
                    anim.SetBool("Rest", true);
                }
            }
            // REST中の処理
            // 現在のベースレイヤーがrestStateの時
            else if (currentBaseState.nameHash == restState)
            {
                //cameraObject.SendMessage("setCameraPositionFrontView");		// カメラを正面に切り替える
                // ステートが遷移中でない場合、Rest bool値をリセットする(ループしないようにする)
                if (!anim.IsInTransition(0))
                {
                    anim.SetBool("Rest", false);
                }
            }
        }
Exemple #19
0
    void Update()
    {
        if (Input.GetKey(KeyCode.L))
        {
            if (posicaoDoJogador.transform.position.x < posicaoDoBoss.transform.position.x) //&& Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 2)
            {
                rigidBodyPlayer.AddForce(Vector3.right * sugada, ForceMode.Acceleration);
                scriptMovimentacao.speed = 1;
                Debug.Log("sugandoCorrotinaEsquerda");
                scriptDash.enabled = false;
            }
            else //(posicaoDoJogador.transform.position.x > posicaoDoBoss.transform.position.x)//&& Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 2)
            {
                rigidBodyPlayer.AddForce(Vector3.left * sugada, ForceMode.Acceleration);
                scriptMovimentacao.speed = 1;
                Debug.Log("sugandoCorrotinaDireita");
                scriptDash.enabled = false;
            }
        }
        if (estaSugando == true)
        {
            if (posicaoDoJogador.transform.position.x < posicaoDoBoss.transform.position.x) //&& Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 2)
            {
                rigidBodyPlayer.AddForce(Vector3.right * sugada, ForceMode.Acceleration);
                scriptMovimentacao.speed = 1;
                Debug.Log("sugandoCorrotinaEsquerda");
                scriptDash.enabled = false;
            }
            else //(posicaoDoJogador.transform.position.x > posicaoDoBoss.transform.position.x)//&& Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 2)
            {
                rigidBodyPlayer.AddForce(Vector3.left * sugada, ForceMode.Acceleration);
                scriptMovimentacao.speed = 1;
                Debug.Log("sugandoCorrotinaDireita");
                scriptDash.enabled = false;
            }
        }
        else
        {
            scriptDash.enabled       = true;
            scriptMovimentacao.speed = 5;
        }
        //transform.Translate(Vector2.right * velocidadeBoss * )
        if (vidaDoBoss.life >= 85)
        {
            Debug.Log("Vida acima de 50");
            //Pular para a direita
            if (podePular == true && Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 10 && posicaoDoJogador.transform.position.x > posicaoDoBoss.transform.position.x) //FUNCIONA
            {
                sorteiaAtaque();
                if (chanceDeAtaque <= 7)
                {
                    StartCoroutine(puloDireita());
                    chanceDeAtaque = 0;
                }

                ///StartCoroutine(cooldownPulo());
                //sugadaEsquerda();
            }

            //Pular para a esquerda
            if (podePular == true && Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 10 && posicaoDoJogador.transform.position.x < posicaoDoBoss.transform.position.x) //FUNCIONA
            {
                sorteiaAtaque();
                if (chanceDeAtaque <= 7)
                {
                    StartCoroutine(puloEsquerda());
                    chanceDeAtaque = 0;
                }

                //StartCoroutine(cooldownPulo());
                //sugadaEsquerda();
            }

            //Cortar
            if (podeCortar == true && Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) < 3)
            {
                StartCoroutine(cooldownCorte());
                corteRapido();
                Debug.Log("cortou!");
            }

            if (Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) < 10 && posicaoDoJogador.transform.position.x > posicaoDoBoss.transform.position.x) //FUNCIONA
            {
                Debug.Log("Ativa Sugada");
                //StartCoroutine(puloEsquerda());
                //StartCoroutine(cooldownPulo());
                //StartCoroutine(ativaSugada());
            }

            /*if (podePular == true)
             * {
             *  StartCoroutine(puloEsquerda());
             *  StartCoroutine(cooldownPulo());
             * }*/
            //Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) < 10 && posicaoDoJogador.transform.position.x > posicaoDoBoss.transform.position.x) //FUNCIONA

            /* {
             * Debug.Log("Ativa Sugada");
             * StartCoroutine(puloEsquerda());
             * //StartCoroutine(cooldownPulo());
             * StartCoroutine(ativaSugada());
             * }*/
        }
        else
        {
            Debug.Log("Vida abaixo de 50, cuidado!");
            if (podePular == true && Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) > 6 && posicaoDoJogador.transform.position.x < posicaoDoBoss.transform.position.x) //FUNCIONA
            {
                Debug.Log("Pula p/ Esquerda");
                StartCoroutine(puloEsquerda());
                StartCoroutine(cooldownPulo());
                //StartCoroutine(ativaSugada());
                //SCRIPT PROIBIDO COM WHILE

                /*if (Vector2.Distance(posicaoDoJogador.position, posicaoDoBoss.position) < 10 && posicaoDoJogador.transform.position.x > posicaoDoBoss.transform.position.x) //FUNCIONA
                 * {
                 *  Debug.Log("Ativa Sugada");
                 *  StartCoroutine(ativaSugada());
                 * }*/
            }
        }
    }
Exemple #20
0
 public void ProcJump()
 {
     // transform.localScale *= 0.98f; // new Vector3(1f, 0.5f, 0.5f);
     //transform.localScale = onSize;
     rb.AddForce(new Vector3(0f, 100000f, 0f));      // 귀엽게 살짝 튀어 오르는 정도.
 }
Exemple #21
0
 public void HitPushForce(Vector3 pushForce)
 {
     _rb.AddForce(pushForce, ForceMode.Impulse);
 }
Exemple #22
0
 public void Fire()
 {
     _rb?.AddForce(transform.forward * _speed, ForceMode.Impulse);
 }
Exemple #23
0
 /// <summary>
 /// Jump action
 /// </summary>
 public void Jump()
 {
     rigid?.AddForce(Vector3.up * 20f, ForceMode.Acceleration);
 }
Exemple #24
0
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.CompareTag("NPC"))
            {
                var npcManager = other.gameObject.GetComponent <NPCManager>();
                if (npcManager.IsChasing())
                {
                    npcManager.StartPunching();
                }
            }

            if (other.gameObject.CompareTag("Hand") && !invincible)
            {
                var npcManager = other.transform.root.gameObject.GetComponent <NPCManager>();
                if (npcManager.IsChasing() && npcManager._npcData.Punching && !Indestructibles.PlayerData.IsKnockedOut)
                {
                    npcManager.OnPlayerHit();
                    // Play a random grunt sound
                    if (gruntSounds.Length > 0)
                    {
                        _audioSource.PlayOneShot(gruntSounds[Random.Range(0, gruntSounds.Length - 1)]);
                    }

                    // Player is dead
                    if (--Indestructibles.PlayerData.HealthPoints <= 0)
                    {
                        Indestructibles.PlayerData.IsKnockedOut = true;
                        _animator.SetTrigger(Animator.StringToHash("Knocked Out"));
                        gameManager.OnPlayerDeath();
                        Indestructibles.PlayerData.IntoxicationLevel = 0.0f;
                        ClearEffects();
                        CancelInvoke(nameof(AddPoint));
                    }
                    else
                    {
                        // Player got hit but is not dead
                        var direction = (transform.position - npcManager.transform.position).normalized;

                        // Temporarily disable root motion to add a push force
                        Indestructibles.PlayerAnimator.applyRootMotion = false;
                        _rigidbody.AddForce(direction * 5.0f, ForceMode.Impulse);
                        Invoke(nameof(EnableRootMotion), 0.5f);

                        invincible = true;
                        Invoke(nameof(DisableInvincible), 2.0f);

                        // Flicker effect
                        InvokeRepeating(nameof(FlickerModel), 0.0f, 0.125f);
                        Invoke(nameof(StopFlicker), 2.0f);

                        // Sober up
                        if (onHitSoberUp)
                        {
                            Indestructibles.PlayerData.IntoxicationLevel -= 0.25f;
                            ClearEffects();
                        }
                    }
                }
                Indestructibles.UIManager.RefreshUI();
            }
        }
    void Update()
    {
#if !UNITY_WEBGL || UNITY_EDITOR
        websocket.DispatchMessageQueue();
#endif
        if (!string.IsNullOrEmpty(messageWB))
        {
            //Debug.Log(messageWB);

            switch (messageWB)
            {
            case "Right":
                if (!PauseMenu.Paused)
                {
                    ballRB.AddForce(Vector3.right * 2);
                }
                break;

            case "Left":
                if (!PauseMenu.Paused)
                {
                    ballRB.AddForce(Vector3.left * 2);
                }
                break;

            case "Front":
                if (!PauseMenu.Paused)
                {
                    ballRB.AddForce(Vector3.forward * 2);
                }
                break;

            case "Back":
                if (!PauseMenu.Paused)
                {
                    ballRB.AddForce(Vector3.back * 2);
                }
                break;

            case "Ŝtop":
                if (!PauseMenu.Paused)
                {
                    ballRB.velocity = Vector3.zero;
                }
                break;

            case "Pause":
                if (!PauseMenu.Paused)
                {
                    PauseMenu.Paused = true;
                    PauseMenu.Change = true;
                }
                break;

            case "Unpause":
                if (PauseMenu.Paused)
                {
                    PauseMenu.Paused = false;
                    PauseMenu.Change = true;
                }
                break;

            case "Up":
                pauseMenu = GameObject.Find("PauseMenu");
                if (PauseMenu.Paused)
                {
                    if (pauseMenu != null)
                    {
                        mainMenu = pauseMenu.GetComponent <MainMenu>();
                        mainMenu.previous();
                        System.Threading.Thread.Sleep(500);
                    }
                }
                break;

            case "Down":
                pauseMenu = GameObject.Find("PauseMenu");
                if (PauseMenu.Paused)
                {
                    if (pauseMenu != null)
                    {
                        mainMenu = pauseMenu.GetComponent <MainMenu>();
                        mainMenu.next();
                        System.Threading.Thread.Sleep(500);
                    }
                }
                break;

            case "Click":
                if (PauseMenu.Paused)
                {
                    pauseMenu = GameObject.Find("PauseMenu");
                    if (pauseMenu != null)
                    {
                        mainMenu = pauseMenu.GetComponent <MainMenu>();
                        mainMenu.current.GetComponent <Button>().onClick.Invoke();
                        System.Threading.Thread.Sleep(500);
                    }
                }
                break;
            }
        }
    }
Exemple #26
0
    void FixedUpdate()
    {
        wind           = WindController.wind;
        rigid.position = new Vector3
                         (
            Mathf.Clamp(rigid.position.x, boundary1stick.xMin, boundary1stick.xMax),
            Mathf.Clamp(rigid.position.y, boundary1stick.yMin, boundary1stick.yMax),
            Mathf.Clamp(rigid.position.z, boundary1stick.zMin, boundary1stick.zMax)
                         );
        Vector3 pos = rigid.position;

        float v_dir = Input.GetAxis("J2-V-Direct");
        float h_dir = Input.GetAxis("J2-H-Direct");

        Vector3 direction = Vector3.zero;

        direction.x = -h_dir;
        direction.y = v_dir;

        angle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg;
        Quaternion rotation = Quaternion.AngleAxis(angle, new Vector3(0f, 0f, -1f));

        recoil = firepoint.transform.position.y < gameObject.transform.position.y ?
                 new Vector3(0f, 0f, 0f) : recoilIntensity * -(firepoint.transform.position - gameObject.transform.position).normalized;

        if (direction.magnitude >= 0.5)
        {
            transform.GetChild(activeTurret).rotation = rotation;
            LastDirection = rotation;
        }
        else
        {
            transform.GetChild(activeTurret).rotation = LastDirection;
        }

        float h_axis = Input.GetAxis("J2-Horizontal");

        if (h_axis != 0)
        {
            MoveAnim.Play("body Animation");
        }

        testbuff();
        if (buff_frozen)//
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = ice;
            buff = 0.6f;
        }
        else
        {
            gameObject.transform.GetChild(0).GetChild(0).GetComponent <MeshRenderer>().material = normal;
            buff = 1f;
        }

        rigid.velocity = new Vector3(buff * Accelrate * h_axis, rigid.velocity.y, 0f);
        rigid.AddForce(Vector3.right * wind * 100);

        if (Input.GetAxis("J2-Fire2") < 0 && remainAmmo >= 1) //fire

        {
            isFireing = true;
        }
        else
        {
            isFireing = false;
        }

        if (isFireing)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter   = timeBetweenShots;
                audioS.volume = 0.3f;

                if (isMulti)
                {
                    special -= 1;
                    bulletMove_2_2 newBullet1 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove_2_2;
                    bulletMove_2_2 newBullet2 = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove_2_2;

                    newBullet1.gameObject.SetActive(true);
                    newBullet1.transform.Translate(new Vector3(0.2f, 0f, 0f));
                    newBullet1.transform.Rotate(new Vector3(0f, 0f, -5f));
                    newBullet1.bulletSpeed = bulletSpeed;
                    newBullet1.SendMessage("SetMulti", true);

                    newBullet2.gameObject.SetActive(true);
                    newBullet2.transform.Translate(new Vector3(-0.2f, 0f, 0f));
                    newBullet2.transform.Rotate(new Vector3(0f, 0f, 5f));
                    newBullet2.bulletSpeed = bulletSpeed;
                    newBullet2.SendMessage("SetMulti", true);

                    //CameraShaker.Instance.ShakeOnce(1.5f, 4f, 0f, 1.5f);
                    rigid.AddForce(1.5f * recoil, ForceMode.Impulse);
                    audioS.pitch = Random.Range(1f, 5f);
                    anim.Play("Double gun Animation");
                }
                else
                {
                    if (isMissile)
                    {
                        special -= 1;
                        MissileMove_2_2 newMissile = Instantiate(missile, firepoint.position, firepoint.rotation) as MissileMove_2_2;
                        newMissile.gameObject.SetActive(true);
                        //CameraShaker.Instance.ShakeOnce(2f, 4f, 0f, 1.5f);
                        anim.Play("Missile Launcher Animation");
                    }
                    else
                    {
                        bulletMove_2_2 newBullet = Instantiate(bullet, firepoint.position, firepoint.rotation) as bulletMove_2_2;
                        newBullet.gameObject.SetActive(true);
                        newBullet.bulletSpeed = bulletSpeed;
                        if (isBig)
                        {
                            audioSB.pitch  = Random.Range(0.2f, 0.3f);
                            audioSB.volume = 1.0f;
                            special       -= 1;
                            newBullet.transform.localScale = new Vector3(1f, 1f, 1f);
                            Animator a = newBullet.GetComponent <Animator>();
                            //                           ParticleSystem p = newBullet.GetComponent<ParticleSystem>();
                            a.enabled = false;
                            newBullet.SendMessage("SetBig", true);
                            //CameraShaker.Instance.ShakeOnce(2.5f, 4f, 0f, 3f);
                            rigid.AddForce(2.0f * recoil, ForceMode.Impulse);
                        }
                        else if (isFrozen)//
                        {
                            special -= 1;
                            newBullet.SendMessage("SetFrozen", true);
                            newBullet.transform.GetChild(0).gameObject.SetActive(true);
                            newBullet.GetComponent <ParticleSystemRenderer>().material = ice;
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                        else
                        {
                            //CameraShaker.Instance.ShakeOnce(1.25f, 4f, 0f, 1.5f);
                            rigid.AddForce(recoil, ForceMode.Impulse);
                            audioS.pitch = Random.Range(1f, 5f);
                        }
                    }
                    anim.Play("Gun Animation");
                }

                SetAmmo(-1);

                if (!isMissile)
                {
                    if (isBig)
                    {
                        audioSB.Play();
                    }
                    else
                    {
                        audioS.Play();
                    }
                }
                else
                {
                    audioM.pitch = Random.Range(0.8f, 1.2f);
                    audioM.Play();
                }
            }
        }
        else
        {
            //shotCounter = 0;
            shotCounter -= Time.deltaTime;
        }
        AmmoCount.SendMessage("SetAmmo", Mathf.Floor(remainAmmo));

        float liftRatio = ((maxLife - 1) / maxLife) * remainLife / maxLife + 1f / maxLife;

        transform.GetChild(0).transform.localScale = new Vector3(1.5f * liftRatio, 0.3f, 0.5f);

        LifeCount.SendMessage("SetLife", remainLife);

        if (remainLife <= 0)
        {
            StartCoroutine(DelayTime(0.3f));
            Time.timeScale = 0.2f;
            Application.targetFrameRate = 150;
            GameObject[] score = GameObject.FindGameObjectsWithTag("Score");
            if (!SetScore)
            {
                score[0].SendMessage("rightPlus");
                SetScore = !SetScore;
            }
        }
        if (isSpecial && special <= 0)
        {
            isBig     = false;
            isMulti   = false;
            isMissile = false;
            isFrozen  = false;//
            gameObject.transform.GetChild(1).transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
            this.transform.GetChild(1).GetChild(1).GetChild(1).gameObject.SetActive(false);
            UseTurret1();
            isSpecial = !isSpecial;
        }

        SpeCount.SendMessage("SetSpe", special);
    }
Exemple #27
0
 private void Start()
 {
     rb.AddForce(250, 0, -500);
 }
Exemple #28
0
 private void Start()
 {
     rb.AddForce(new Vector3(1, 1, 0) * Force);
 }
Exemple #29
0
 void Start()
 {
     dir = new Vector3(0, 0, 1);
     rig = GetComponent <Rigidbody>();
     rig.AddForce(dir * (HudScr.speedBrick + 1000));
 }
    // Update is called once per frame
    public void Update()
    {
        if (movementEnabled) //if the player has not reached the end of the level, movement controls are enabled
        {
            self.AddForce(0.0f, 0.0f, Input.GetAxis("Horizontal") * speed);

            //When the player is presses the space key while in range of a grapple point, the score increases by 10 and calls the method "Connect()"
            //When the space key is released, it calls the method "Disconnect()"

            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (isInRange)
                {
                    if (!connected)
                    {
                        PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score") + 10);
                        SendMessage("UpdateScore");
                        Connect();
                    }
                }
            }
            if (Input.GetKeyUp(KeyCode.Space))
            {
                if (isInRange)
                {
                    DisConnect();
                }
            }
        }

        //When losing a life or advancing a level, the UI hearts are changed to the empty heart sprite.
        //When the player runs out of lives, movement controls are disabled and the Game Over UI appears
        switch (PlayerPrefs.GetInt("Lives"))
        {
        case 4:
            life1.sprite = lifeloss;
            break;

        case 3:
            life1.sprite = lifeloss;
            life2.sprite = lifeloss;

            break;

        case 2:
            life1.sprite = lifeloss;
            life2.sprite = lifeloss;
            life3.sprite = lifeloss;

            break;

        case 1:
            life1.sprite = lifeloss;
            life2.sprite = lifeloss;
            life3.sprite = lifeloss;
            life4.sprite = lifeloss;

            break;

        case 0:
            life5.sprite    = lifeloss;
            movementEnabled = false;
            gameOverSprite.SetActive(true);
            break;
        }


        //When the player makes contact with the finishing platform and the E key is pressed, the player advances to 1 of 5 levels chosen at random and the score is increased by 100
        if (LevelFinished)
        {
            if (Input.GetKey(KeyCode.E))
            {
                int randomLevel = Random.Range(1, 5);

                PlayerPrefs.SetInt("Score", PlayerPrefs.GetInt("Score") + 100);

                print(PlayerPrefs.GetInt("Score"));

                SendMessage("UpdateScore");

                SceneManager.LoadScene(randomLevel);
            }
        }
    }