Пример #1
0
    private void AimAtMouse()
    {
        float rayDistance;

        //Create a ray which starts at the camera and goes through the mouses position
        Ray camToMouseRay = m_Camera.ScreenPointToRay(Input.mousePosition);

        //Create a plane so that the ray can be intersected.
        Plane plane = new Plane(Vector3.up, transform.position);

        //If the ray interscets with the plane then return true and determine the distance between the intersection position and the origin
        if (plane.Raycast(camToMouseRay, out rayDistance))
        {
            //Create a point where the ray intersects
            Vector3 point = camToMouseRay.GetPoint(rayDistance);

            //Have the player look at the point on the x and z axis.
            transform.LookAt(new Vector3(point.x, transform.position.y, point.z));

            // Check when the mouse is near the player and as such make the gun stop looking to avoid weird rotation
            //CheckGunToMouseDistance(point);

            m_WeaponController.Aim(point);
        }
    }
Пример #2
0
    void Update()
    {
        if (!stunned)
        {
            if (target != null)
            {
                aimDir = (target.position - transform.position).normalized;

                if (controlsInverted)
                {
                    aimDir *= -1;
                }
            }

            if (!inputSet)
            {
                isFirePressed = Physics2D.Raycast(transform.position, aimDir, range, targetMask);

                if (isFirePressed)
                {
                    inputSet = true;
                    StartCoroutine(SwitchTrigger());
                }
            }
        }

        currentWeapon.Aim(aimDir);
        currentWeapon.Shoot(isFirePressed);
    }
    public override void InstructionCycle()
    {
        if (weaponController != null)
        {
            weaponController.Tick();
        }
        StateMachine();

        if (weaponController != null)
        {
            if (state.action == EntityAction.Aiming && CanAim(state.aimCurrent) == true)
            {
                weaponController.Aim(state.aimCurrent);
            }
            else
            {
                weaponController.AtEase();
            }

            if (input.attackStartRequest == true)
            {
                weaponController.OnTriggerPull();
            }
            if (input.attackStopRequest == true)
            {
                weaponController.OnTriggerRelease();
            }
            if (input.reloadRequest == true)
            {
                weaponController.Reload();
            }
        }

        Interact();
    }
Пример #4
0
    void Update()
    {
        //movement input
        checkHorizontal();
        checkVertical();
        float x = Input.GetAxisRaw("Horizontal"); //get key input for x
        float y = Input.GetAxisRaw("Vertical");   //get key input for y

        controller.MoveX(x);
        controller.MoveY(y);
        controller.Dashing(dashing);

        //Look input
        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition); //cast a ray from camera to mouse cursor
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * weaponController.WeaponHeight);
        float rayDistance;                                                    //distance from ray to cursor

        if (groundPlane.Raycast(ray, out rayDistance))                        //pass in the ray and get the rayDistance
        {
            Vector3 point = ray.GetPoint(rayDistance);                        //get rayDistance and save to point
            Debug.DrawLine(ray.origin, point, Color.red);
            controller.LookAt(point);                                         //run PlayerController's "LookAt" function
            crosshair.transform.position = point;                             //set position of cursor to point
            crosshair.DetectTargets(ray);                                     //run Crosshair's "DetectTarget" function

            //if cursor position is not close to player(to prevent wierd behaviour when weapon aims to near at player)
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1)
            {
                weaponController.Aim(point); //aim weapon at the cursor point
            }
        }

        //weapon input
        if (Input.GetMouseButton(0))
        {
            weaponController.OnTriggerHold(); //run WeaponController's "OnTriggerHold" function
        }

        if (Input.GetMouseButtonUp(0))
        {
            weaponController.OnTriggerRelease(); //run WeaponController's "OnTriggerRelease" function
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            weaponController.Reload(); //run WeaponController's "Reload" function
        }

        if (transform.position.y <= -10) //if player fall out the map
        {
            TakeDamage(health);          //player die
        }

        if (Input.GetKeyDown(KeyCode.Escape) && sceneName == "Game") //if player press escape at game scene
        {
            Cursor.visible = true;                                   //set cursor to visible
            SceneManager.LoadScene("Menu");                          //return to menu
        }
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
        {
            LockedCamMode = false;
        }
        else
        {
            LockedCamMode = true;
        }


        if (LockedCamMode)
        {
            weaponController.Aim(aimSystem.AimSpherePoint(Camera.main.ScreenPointToRay(Input.mousePosition)));

            var h = Input.mousePosition.x / Screen.width;
            var v = Input.mousePosition.y / Screen.height;
            if (h < 0.25f)
            {
                cameraController.RotationUpdate(-1);
            }
            else if (h > 0.75f)
            {
                cameraController.RotationUpdate(1);
            }
            if (v < 0.2f)
            {
                cameraController.AngleUpdate(1);
            }
            else if (v > 0.8f)
            {
                cameraController.AngleUpdate(-1);
            }
        }
        else
        {
            cameraController.AngleUpdate(Input.GetAxis("Mouse Y"));
            cameraController.RotationUpdate(Input.GetAxis("Mouse X"));
        }

        UpdateAimingCursor(LockedCamMode);

        cameraController.CameraDistanceUpdate(Input.mouseScrollDelta.y);

        if (Input.GetMouseButtonDown(0))
        {
            weaponController.Shoot(gameObject);
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
Пример #6
0
    void Update()
    {
        // The code below allows the player's "eyes" to follow the mouse movement.
        Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
        //  Debug.DrawLine(ray.origin, point, Color.red);

        // Emulate the playing surface by creating a new, flat plane. This simplifies the code as we
        // don't have to depend on the actual in-game plane.
        //
        // `Vector3.up` Shorthand for writing `Vector3(0, 1, 0)`.
        Plane plane = new Plane(Vector3.up, Vector3.up * weaponController.weaponHold.position.y);
        float rayLength;

        // This function sets enter to the distance along the ray, where it intersects the plane. If the
        // ray is parallel or pointing in the opposite direction to the plane then `Raycast()` is false
        // and `rayLength` is 0 and negative, respectively.
        if (!plane.Raycast(ray, out rayLength))
        {
            return;
        }

        const int threshold   = 6;
        Vector3   point       = ray.GetPoint(rayLength);
        Vector2   newPoint    = new Vector2(point.x, point.z);
        Vector2   newPosition = new Vector2(transform.position.x, transform.position.z);

        playerController.LookAt(point);

        if ((newPoint - newPosition).sqrMagnitude > threshold)
        {
            weaponController.Aim(point);
        }

        crossHair.transform.position = point;
        crossHair.DetectTargets(ray);

        ScanInput();
        Move();
    }
Пример #7
0
    public void GunManagement()
    {
        WeaponController gun = GetComponent <WeaponController>();

        if (Input.GetMouseButtonDown(0))
        {
            gun.Shoot();
        }

        if (Input.GetAxis("Pistol") > 0)
        {
            gun.ChangeGun(1);
        }
        if (Input.GetAxis("AssaultRifle") > 0)
        {
            gun.ChangeGun(2);
        }
        if (Input.GetAxis("SniperRifle") > 0)
        {
            gun.ChangeGun(3);
        }
        if (Input.GetAxis("Recharge") > 0)
        {
            gun.Recharge();
        }
        if (Input.GetMouseButtonDown(1))
        {
            if (gun.equippedGun.name == "SniperRifle")
            {
                gun.AimRifle();
            }
            else
            {
                gun.Aim();
            }
        }
    }
    void Update()
    {
        if (currentWeapon == null && bonusActive)
        {
            bonusActive   = false;
            currentWeapon = bonusWeapon;
            currentWeapon.gameObject.SetActive(true);
            bonusWeapon = null;
        }

        if (!stunned)
        {
            Vector2 aimDir = new Vector2(InputSystem.ThumbstickInput(ThumbSticks.RightX, playerNr - 1), InputSystem.ThumbstickInput(ThumbSticks.RightY, playerNr - 1));

            if (controlsInverted)
            {
                aimDir *= -1;
            }

            currentWeapon.Aim(aimDir);
        }

        currentWeapon.Shoot(InputSystem.TriggerPressed(Triggers.Right, playerNr - 1));

        if (ability != null)
        {
            if (InputSystem.TriggerUp(Triggers.Left, playerNr - 1))
            {
                ability.StopUse();
            }
            else if (InputSystem.TriggerPressed(Triggers.Left, playerNr - 1) && specialAvailable)// && !sprintActive)
            {
                ability.Use();
            }
        }
    }