Ejemplo n.º 1
0
    // Fixed update is called in sync with physics
    private void FixedUpdate()
    {
        // read inputs
        h      = CrossPlatformInputManager.GetAxis("Horizontal");
        v      = CrossPlatformInputManager.GetAxis("Vertical");
        crouch = Input.GetKey(KeyCode.C);
        if ((h < -offsetCross || h > offsetCross || v < -offsetCross || v > offsetCross) && aim)
        {
            cameraFunctions.WiggleCrosshairAndCamera(weaponManager.ActiveWeapon, false);
        }
        lookPos = lookInCameraDirection && m_Cam != null ? transform.position + m_Cam.forward * 100 : transform.position + transform.forward * 100;

        if (!aim)
        {
            // calculate move direction to pass to character
            if (m_Cam != null)
            {
                // calculate camera relative direction to move:
                m_CamForward = Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized;
                m_Move       = v * m_CamForward + h * m_Cam.right;
            }
            else
            {
                // we use world-relative directions in the case of no main camera
                m_Move = v * Vector3.forward + h * Vector3.right;
            }
#if !MOBILE_INPUT
            // walk speed multiplier
            if (Input.GetKey(KeyCode.LeftShift))
            {
                m_Move *= 0.5f;
            }
#endif

            // pass all parameters to the character control script
            m_Character.Move(m_Move, crouch, m_Jump, aim, lookPos);
            m_Jump = false;
            m_CharacterAim.m_Jump = false;
        }
        else
        {
            var go = gameObject.GetComponentInChildren <Animator>().gameObject.transform;
            //var yo = gameObject.GetComponentInChildren<Animator>().gameObject.transform;
            //Debug.Log(go.name);
            m_Move = Vector3.zero;

            Vector3 dir = lookPos - go.position;
            dir.y       = 0;
            go.rotation = Quaternion.Slerp(go.rotation, Quaternion.LookRotation(dir), 5 * Time.deltaTime);
            //yo.localRotation = Quaternion.Slerp(go.localRotation, Quaternion.LookRotation(dir), 5 * Time.deltaTime);
            m_CharacterAim.ChangeMovementScript(h, v, Vector3.Scale(m_Cam.forward, new Vector3(1, 0, 1)).normalized, m_Cam.right, a_wanttorun);
            anim.SetBool("Crouch", crouch);
            m_Jump = false;
            m_CharacterAim.m_Jump = false;
        }
    }
Ejemplo n.º 2
0
    void Attack()
    {
        agent.Stop();
        anim.SetFloat("Turn", 0);
        anim.SetFloat("Forward", 0);
        weaponManager.aim = true;
        anim.SetBool("Aim", true);
        charMove.Move(Vector3.zero, false, false, true, Vector3.zero);
        Vector3 direction = lastKnownPosition - transform.position;
        float   angle     = Vector3.Angle(direction, transform.forward);

        if (angle < 180f)
        {
            //Debug.Log("Enemy looking at you!!!" + lastKnownPosition.ToString());
            transform.LookAt(lastKnownPosition);
        }
        attackTimer += Time.deltaTime;
        if (attackTimer > attackRate)
        {
            if (SharedFunctions.CheckAmmo(weaponManager.ActiveWeapon))
            {
                timesFired++;
                ShootRay();
            }
            else
            {
                if (SharedFunctions.ReturnRandomInt() <= 5)
                {
                    anim.SetTrigger("Reload");
                    weaponManager.ReloadActiveWeapon();
                }
                else
                {
                    weaponManager.ChangeWeapon(true);
                }
            }
            attackTimer = 0;
        }
    }
 void RpcMove(Vector3 move)
 {
     m_Player.Move(move);
 }