void Turning()
    {
        if (!isLocalPlayer)
        {
            return;
        }

        Ray        camRay = playerCamera.ScreenPointToRay(Input.mousePosition);
        RaycastHit floorHit;

        if (Physics.Raycast(camRay, out floorHit, camRaylenght, floorMask))
        {
            playerToMouse   = floorHit.point - transform.position;
            playerToMouse.y = 0f;

            Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
            playerRigidbody.MoveRotation(newRotation);

            float angle = AimCone.GetAngle(Statistics, GetSpeed() / 3) / 2;
            //Debug.Log("Cone angle: " + angle + ", player speed: " + GetSpeed());

            LineRenderer lineRenderer = GetComponent <LineRenderer>();
            Vector3      point1       = Quaternion.AngleAxis(angle, Vector3.up) * playerToMouse;
            point1.y = 0f;
            Vector3 point2 = Quaternion.AngleAxis(-angle, Vector3.up) * playerToMouse;
            point2.y = 0f;
            lineRenderer.SetPosition(0, transform.position + AimCone.lineLength * point1.normalized);
            lineRenderer.SetPosition(2, transform.position + AimCone.lineLength * point2.normalized);
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        // Add the time since Update was last called to the timer.
        timer += Time.deltaTime;
        bool attack  = Input.GetButton("Fire1") && (!craftmenu.activeSelf);
        bool canFire = (_equipmentManager.CanFire() && currentWeapon.IsAmmoNeeded());

        if (!attack || !canFire)
        {
            anim.SetBool("attack", false);
        }

        // If the Fire1 button is being press and it's time to fire...
        if (isLocalPlayer && canFire && attack && timer >= currentWeapon.getTimeBetweenBullet())
        {
            // ... shoot the gun  and start animation
            anim.SetBool("attack", true);
            //isAnimationWorking = true;
            if (anim.GetLayerWeight(currentWeapon.GetLayerNumber()) != 1.0f)  // if not active yet

            {
                Debug.LogError("Je passe ici");
                resetWeight();
                anim.SetLayerWeight(currentWeapon.GetLayerNumber(), 1.0f);
            }
            isShooting = true;
            currentWeapon.SetCanHit(isShooting);
        }
        else if (attack && !canFire)
        {
            Debug.LogError("Not enough ammo!");
            playerInfo.DisplayMessage("error", "Pas assez de munitions.");
        }

        if (anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).IsName(currentWeapon.GetLayerName()) && anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).normalizedTime > currentWeapon.GetFiringTime() && isShooting && canFire) // Firing during the animation
        {
            timer = 0f;
            float angle = AimCone.GetAngle(Statistics, PlayerMovement.GetSpeed() / 3) / 2;
            currentWeapon.Fire(angle);
            isShooting = false;
            _equipmentManager.RemoveAmmo();
        }

        /* if(anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).IsName(currentWeapon.GetLayerName()) && anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).normalizedTime > .99f && isAnimationWorking ) // reset timer when animation is finished
         * {
         *   isAnimationWorking = false;
         *   timer = 0f;
         * }*/

        if (timer >= currentWeapon.getTimeBetweenBullet() * currentWeapon.getEffectsDisplayTime())
        {
            // ... disable the effects.
            currentWeapon.DisableEffects();
        }
    }