Beispiel #1
0
    private void RotateView()
    {
        //Quaternion rotation = Quaternion.AngleAxis(180, m_Camera.transform.up);
        Quaternion player = cache_tf.localRotation;
        Quaternion cam    = m_Camera.transform.localRotation;

        m_MouseLook.LookRotation(ref player, ref cam);

        cache_tf.localRotation = player;
        //b_Camera.transform.localRotation = rotation * cam;
        m_Camera.transform.localRotation = cam;
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        if (attacker != null && lookCamera != null)
        {
            // TODO:  Move the turret to the mouselook location...slowly
            MouseLook.LookRotation(transform, lookCamera.transform, lookCamera.fieldOfView / maxFoV);

            //TODO:  Kind of kludgey

            var ray = lookCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0.0f));
            gameEventSystem.RaiseEvent(GameEventType.TargetOrientationChanged, attacker.gameObject, ray);

            if (Input.GetAxis("Zoom") != 0)
            {
                float fov = targetFoV - (Input.GetAxis("Zoom") * sensitivityZ * Time.deltaTime * (targetFoV / minFoV));
                targetFoV = Mathf.Clamp(fov, minFoV, maxFoV);
            }

            if (Input.GetButton("Fire1")) // todo move to down?
            {
                // Fire the shot
                // leave attack mode
                // enter shot cam mode

                // TODO: Accuracy on shot, perhaps pass in here.

                bulletCamState.TargetProjectile = attacker.FireWeapon();



                var bulletCollider = bulletCamState.TargetProjectile.GetComponent <Collider>();
                foreach (var attackerCollider in attacker.GetComponentsInChildren <Collider>())
                {
                    Physics.IgnoreCollision(bulletCollider, attackerCollider);
                }

                playerController.ReplaceState(bulletCamState);
            }
            else if (Input.GetButton("Fire2"))
            {
                playerController.PopCurrentState();
            }
        }

        if (lookCamera.fieldOfView != targetFoV)
        {
            lookCamera.fieldOfView = Mathf.MoveTowards(lookCamera.fieldOfView, targetFoV, ZoomRate);
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        m_MouseLook.LookRotation(transform, m_Camera.transform);

        if (!m_PreviouslyGrounded && m_CharacterController.isGrounded)
        {
            m_MoveDir.y = 0f;
            m_Jumping   = false;
        }
        if (!m_CharacterController.isGrounded && !m_Jumping && m_PreviouslyGrounded)
        {
            m_MoveDir.y = 0f;
        }
        //Debug.Log("m_PreviouslyGrounded = " + m_PreviouslyGrounded);
        //Debug.Log("m_CharacterController.isGrounded = " + m_CharacterController.isGrounded);

        m_PreviouslyGrounded = m_CharacterController.isGrounded;


        float h = InputManager.GetAxis("Horizontal");
        float v = InputManager.GetAxis("Vertical");

        m_Input = new Vector2(h, v);
        if (m_Input.sqrMagnitude > 1)
        {
            m_Input.Normalize();
        }

        Vector3    desiredMove = transform.forward * m_Input.y + transform.right * m_Input.x;
        RaycastHit hitInfo;

        Physics.SphereCast(transform.position, m_CharacterController.radius, Vector3.down, out hitInfo,
                           m_CharacterController.height / 2f, ~0, QueryTriggerInteraction.Ignore);
        desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;
        m_MoveDir.x = desiredMove.x * speed;
        m_MoveDir.z = desiredMove.z * speed;
        //Debug.Log("m_Jump = " + m_Jump);
        //Debug.Log("m_Jumping = " + m_Jumping);
        if (InputManager.GetButtonDown("Jump"))
        {
            Debug.Log("11111111111111111111111111111111111111111111111111111111111111111111");
        }
        if (!m_Jump && !m_Jumping)
        {
            m_Jump = InputManager.GetButtonDown("Jump");
        }

        if (m_CharacterController.isGrounded)
        {
            m_MoveDir.y = -m_StickToGroundForce;

            if (m_Jump)
            {
                m_MoveDir.y = m_JumpSpeed;
                m_Jump      = false;
                m_Jumping   = true;
            }
        }
        else
        {
            m_MoveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime;
        }

        m_CharacterController.Move(m_MoveDir * Time.fixedDeltaTime);
        //UpdateMousePosition();
        m_MouseLook.UpdateCursorLock();
    }