Ejemplo n.º 1
0
    // Update is called once per frame
    public void FixedUpdate()
    {
        // basic stick based movement
        inputVector = new Vector3(rewiredPlayer.GetAxis("MoveHorizontalX"), 0, rewiredPlayer.GetAxis("MoveHorizontalY"));
        //inputVector = player.transform.TransformDirection(inputVector);

        // In order to properly get the bumper buttons you MUST set them manually through the inspector, they are next to each other near the joystick 1 definitions
        // up and down movement

        if (rewiredPlayer.GetButton("RightBumper"))
        {
            // move up
            inputVector.y += 1;
        }

        if (rewiredPlayer.GetButton("LeftBumper"))
        {
            // move down
            inputVector.y -= 1;
        }

        if (Input.GetKey(KeyCode.W))
        {
            // for playtesting without a controller
            inputVector.z += 1;
        }

        inputVector = player.transform.TransformDirection(inputVector);

        playerBody.velocity = inputVector * (player.speed * 50) * Time.deltaTime;
    }
Ejemplo n.º 2
0
 // Update is called once per frame
 private void Update()
 {
     if (canMove && !GameManager.Instance.isPaused && (!PhotonNetwork.IsConnected || (PhotonNetwork.IsConnected && photonView.IsMine)))
     {
         input = ReadMovement();
         if (PhotonNetwork.IsConnected && player != null)
         {
             if (player.GetButtonDown(RewiredConsts.Action.Dash) && playerStatus == PlayerStatus.None)
             {
                 photonView.RPC(nameof(Dash), RpcTarget.All);
             }
             else if (player.GetButtonDown(RewiredConsts.Action.Charge) && playerStatus == PlayerStatus.None)
             {
                 AssignChargeCoroutine();
                 photonView.RPC(nameof(Move), RpcTarget.All);
             }
             else if ((player.GetButtonDown(RewiredConsts.Action.Swing) && playerStatus == PlayerStatus.None) || (chargeCoroutine != null && (player.GetButtonUp(RewiredConsts.Action.Charge) || !player.GetButton(RewiredConsts.Action.Charge))))
             {
                 StopChargeCoroutine();
                 photonView.RPC(nameof(Swing), RpcTarget.All, orientation, currentCharge);
                 //ReleaseCharge(Color.white);
             }
             else
             {
                 //Regular movement
                 photonView.RPC(nameof(Move), RpcTarget.All);
             }
         }
         else if (player != null)
         {
             if (player.GetButtonDown(RewiredConsts.Action.Dash) && playerStatus == PlayerStatus.None)
             {
                 Dash();
             }
             else if (player.GetButtonDown(RewiredConsts.Action.Charge) && playerStatus == PlayerStatus.None)
             {
                 AssignChargeCoroutine();
                 Move();
             }
             else if ((player.GetButtonDown(RewiredConsts.Action.Swing) && playerStatus == PlayerStatus.None) || (chargeCoroutine != null && (player.GetButtonUp(RewiredConsts.Action.Charge) || !player.GetButton(RewiredConsts.Action.Charge))))
             {
                 StopChargeCoroutine();
                 Swing(orientation, currentCharge);
                 //ReleaseCharge(Color.white);
             }
             else
             {
                 //Regular movement
                 Move();
             }
         }
     }
     else if (PhotonNetwork.IsConnected && !photonView.IsMine)
     {
         transform.position = Vector3.Lerp(transform.position, networkPosition, networkDistance * (1f / PhotonNetwork.SerializationRate));
     }
 }
Ejemplo n.º 3
0
        private void Poll(InputPlayer player, InputEventPollingType pollingType)
        {
            InputReceiver receiver = _receivers[player];

            if (receiver == null)
            {
                return;
            }

            Rewired.Player rePlayer = ReInput.players.GetPlayer((int)receiver.InputPlayer);
            foreach (var action in ReInput.mapping.Actions)
            {
                if (rePlayer.GetButtonDown(action.id))
                {
                    _receivers[player]?.ReceiveButtonEvent(new InputActionEvent(action.id, pollingType, InputEventType.Down));
                }
                if (rePlayer.GetButtonUp(action.id))
                {
                    _receivers[player]?.ReceiveButtonEvent(new InputActionEvent(action.id, pollingType, InputEventType.Up));
                }
                if (rePlayer.GetButton(action.id))
                {
                    _receivers[player]?.ReceiveButtonEvent(new InputActionEvent(action.id, pollingType, InputEventType.Hold));
                }

                _receivers[player]?.ReceiveAxisEvent(rePlayer.GetAxis(action.id), new InputAxisEvent(action.id, pollingType));
            }
        }
    // Update is called once per frame
    void Update()
    {
        if (!isReady)
        {
            //check1.SetActive(gamePadController1.GetButton("Jump")); // visual check for player 1
            //check2.SetActive(gamePadController2.GetButton("Jump")); // visual check for player 2
            toggleConfirmation(check1, gamePadController1); // visual check for player 1
            toggleConfirmation(check2, gamePadController2); // visual check for player 2
        }

        // Go To Game Scene
        if (gamePadController1.GetButton("Jump") && gamePadController2.GetButton("Jump") || Input.GetKeyDown(KeyCode.Return))
        {
            isReady = true;
            toggleConfirmation(check1, null, true); // visual check for player 1
            toggleConfirmation(check2, null, true); // visual check for player 2
            IEnumerator fadeSound = AudioFadeOut.FadeOut(sound, 2.0f);
            StartCoroutine(fadeSound);
            SceneChanger.setSceneIndexSelected(SceneChanger.GAME);
            FindObjectOfType <SceneChanger>().GetComponent <Animator>().SetTrigger("FadeOut");
        }

        // Go Back To Main Menu Scene
        if (gamePadController1.GetButtonDown("Camera Flip") || gamePadController2.GetButtonDown("Camera Flip"))
        {
            SceneChanger.setSceneIndexSelected(SceneChanger.MENU);
            FindObjectOfType <SceneChanger>().GetComponent <Animator>().SetTrigger("FadeOut");
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (!isReady)
        {
            toggleConfirmation(check1, gamePadController1); // visual check for player 1
            toggleConfirmation(check2, gamePadController2); // visual check for player 2
        }

        // Go To Game Scene
        if (gamePadController1.GetButton("Menu Ready") && gamePadController2.GetButton("Menu Ready")) //|| Input.GetKeyDown(KeyCode.Return))
        {
            isReady = true;
            toggleConfirmation(check1, null, true); // visual check for player 1
            toggleConfirmation(check2, null, true); // visual check for player 2

            //IEnumerator fadeSound = AudioFadeOut.FadeOut(sound, 2.0f);
            //StartCoroutine(fadeSound);
            //SceneChanger.setSceneIndexSelected(SceneChanger.GAME);
            //FindObjectOfType<SceneChanger>().GetComponent<Animator>().SetTrigger("FadeOut");
            //gameObject.SetActive(false);
            FindObjectOfType <CanvasAnimationEvents>().GetComponent <Animator>().SetTrigger("Start Game");
        }

        // Go Back To Main Menu Scene

        /*
         * if (gamePadController1.GetButtonDown("Camera Flip") || gamePadController2.GetButtonDown("Camera Flip"))
         * {
         *  SceneChanger.setSceneIndexSelected(SceneChanger.MENU);
         *  FindObjectOfType<SceneChanger>().GetComponent<Animator>().SetTrigger("FadeOut");
         * }
         */

        instructionsScroll();
    }
Ejemplo n.º 6
0
 public static bool MenuAccept(Rewired.Player p)
 {
     // can add other buttons to this condition, so leaving it like this
     if (p.GetButton("Fire"))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 7
0
    public override bool GetButton(int button)
    {
        if (!isEnabled)
        {
            return(false);
        }

        return(input.GetButton(button));
    }
Ejemplo n.º 8
0
    private void Update()
    {
        Vector3 inputDirection = new Vector3(_input.GetAxis(RewiredConsts.Action.Horizontal), 0, _input.GetAxis(RewiredConsts.Action.Vertical));

        if (inputDirection.sqrMagnitude > float.Epsilon)
        {
            _rigidbody.MoveRotation(Quaternion.LookRotation(inputDirection, Vector3.up));
        }

        _inputMove = _input.GetButton(RewiredConsts.Action.Move);
    }
Ejemplo n.º 9
0
    private void Update()
    {
        if (!Rewired.ReInput.isReady)
        {
            return;
        }

        Rewired.Player player = Rewired.ReInput.players.GetPlayer(0);

        if (IsDragging)
        {
            // If current dragged thing was destroyed, cancel drag
            if (_currentDraggable == null)
            {
                StopDrag();
                return;
            }

            float   distanceScale  = Vector3.Distance(Camera.main.transform.position, _currentDraggable.position);
            float   horizontalAxis = player.GetAxis("CursorX") * Time.deltaTime * _handDragSensitivity;
            float   verticalAxis   = player.GetAxis("CursorY") * Time.deltaTime * _handDragSensitivity;
            Vector3 cameraMovement = Camera.main.transform.position - _dragStartCameraPos;
            _targetHandPos     += Camera.main.transform.right.WithY(0).normalized *horizontalAxis *distanceScale;
            _targetHandPos     += Camera.main.transform.forward.WithY(0).normalized *verticalAxis *distanceScale;
            _targetHandPos     += cameraMovement;
            _targetHandPos.y    = _handDragHeight;
            _dragStartCameraPos = Camera.main.transform.position;

            _isRotating = player.GetButton("Context");
        }
        else
        {
            Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            bool       hit = Physics.Raycast(mouseRay, out hitInfo, 100.0f, _raycastMask);
            if (hit)
            {
                _targetHandPos = hitInfo.point + hitInfo.normal * _handHoverDistance;

                if (player.GetButtonDown("Select"))
                {
                    StartDrag(hitInfo);
                }
            }
        }

        if (player.GetButtonUp("Select"))
        {
            StopDrag();
        }

        _handObject.transform.position = Mathfx.Damp(_handObject.transform.position, _targetHandPos, 0.5f, Time.deltaTime * _handAnimateSpeed);
    }
Ejemplo n.º 10
0
        public void Run_Update(On.RoR2.Run.orig_Update orig, Run self)
        {
            orig.Invoke(self);

            //Check if player is moving in any Axis
            float vert = inputPlayer.GetAxis("MoveVertical");
            float horz = inputPlayer.GetAxis("MoveHorizontal");

            //Rework so it works better with controller
            float move = vert != 0 ? .5f : horz != 0 ? .5f : 0;

            float sprint = move == 0 ? 0f : characterBody.isSprinting ? .4f : 0;

            //Check if player is litteraly pressing moving button (Jumping, Skills)
            float skill = inputPlayer.GetButton("PrimarySkill") ? .75f :
                          inputPlayer.GetButton("SecondarySkill") ? .75f :
                          inputPlayer.GetButton("UtilitySkill") ? .75f :
                          inputPlayer.GetButton("SpecialSkill") ? .75f :
                          inputPlayer.GetButton("Jump") ? .75f :
                          inputPlayer.GetButton("Equipment") ? .75f : 0;

            float onGround = characterMotor.isGrounded ? 0f : .25f;

            //Calculate Time
            //Gotta rework this sheit
            float time = onGround + skill + move + sprint;

            if (time > 1f)
            {
                time = 1f;
            }

            ExampleCommandHostCustom.Invoke(x => { x.Write("Time"); x.Write((double)time); });
        }
Ejemplo n.º 11
0
    /*public void changeGroundState(bool newState)
     * {
     *  isGrounded = newState;
     * }*/

    private void Update()
    {
        if (rewiredPlayer.GetButton(RewiredConsts.Action.Jump))
        {
            timer += Time.deltaTime;
        }
        else if (rewiredPlayer.GetButtonUp(RewiredConsts.Action.Jump))
        {
            timer = 0;
        }
        if (isjumping)
        {
            if (timer > 0.3f)
            {
                ActivateFlying();
            }
        }
        if (canUseJetpack)
        {
            JetPack();
        }
    }
        protected override void OnUpdate()
        {
            if (input.GetButtonDown(PlayerInputActions.Shift))
            {
                begin();
            }
            else if (input.GetButtonUp(PlayerInputActions.Shift))
            {
                end();
            }

            if (input.GetButton(PlayerInputActions.Shift))
            {
                update();
            }
        }
Ejemplo n.º 13
0
    private void OnTriggerEnter2D(Collider2D col)
    {
        if ((col.tag == "MenuMouse") && (player.GetButton("Click")))
        {
            switch (buttonType)
            {
            case "options":
                Debug.Log("options highlighted");
                mainMenuManager.OptionsMenuToggle();
                break;

            case "play":
                mainMenuManager.StartPlay();
                break;

            case "exit":
                Application.Quit();
                break;
            }
        }
    }
Ejemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        thrust = maxThrust;
        thrust = Mathf.Clamp(thrust, 0, maxThrust);
        if (engines.Running)
        {
            Vector3 movementInput = new Vector3(0, 0, thrust);
            movementInput      = aimSpace.TransformVector(movementInput);
            controller.Pushing = movementInput.sqrMagnitude > 0.25f * 0.25f;
            controller.AddForceRelative(movementInput.normalized);
        }

        Vector3 rotationInput = new Vector3(
            player.GetAxis("Pitch"),
            player.GetAxis("Yaw"),
            player.GetAxis("Roll")
            );

        controller.Spinning = rotationInput.sqrMagnitude > 0.25f * 0.25f;
        controller.AddTorqueRelative(Vector3.Scale(rotationInput, controller.Drifting?driftingRotationFactors:rotationFactors));

        if (player.GetButtonDown("Slow Mo") && engines.Running)
        {
            engines.TurnOff();
        }
        if (player.GetButtonDown("Start Engine") && !engines.Running)
        {
            engines.TurnOn();
        }

        if (player.GetButton("Fire"))
        {
            Missile m = guns.Fire();
            if (m != null)
            {
                m.SetTarget(targetingSystem.GetLockedTarget());
            }
        }
    }
    /// <summary>
    /// Basic shooting. Override for Soldier and Engineer
    /// </summary>
    protected virtual void ShootingInput()
    {
        if (!_canShoot)
        {
            return;
        }

        if (_player.GetButton("Shoot") && Time.time >= _strapTimer && _curClip > 0)
        {
            _strapTimer = Time.time + _fireRate;
            Instantiate(_bulletPrefab, _attackPoint.transform.position, _attackPoint.transform.rotation);
            _shot = true;
            _gunshot.Play();
            _curClip--;
        }
        if (_player.GetButton("Shoot") && _curClip > 0)
        {
            _curMoveSpeed = _movementSpeed * 0.5f;
        }
        else
        {
            _curMoveSpeed = _movementSpeed;
        }
    }
 private void HandleBoost()
 {
     if ((Input.GetKey(KeyCode.Space) || player.GetButton("Boost")) && EnergySystem.instance.Boost())
     {
         if (Input.GetKeyDown(KeyCode.Space) || player.GetButtonDown("Boost"))
         {
             SoundPool.instance.PlaySound(SoundClips.instance.Boost, transform.position, false, false, 0.25f);
         }
         currentSpeedNormalized += boostSpeed;
         if (currentSpeedNormalized >= 1f)
         {
             currentSpeedNormalized = 1f;
         }
     }
     else
     {
         currentSpeedNormalized -= decelerateSpeed;
         if (currentSpeedNormalized <= 0f)
         {
             currentSpeedNormalized = 0f;
         }
     }
 }
Ejemplo n.º 17
0
    private void FixedUpdate()
    {
        xPos = playerController.GetAxis("MoveHorizontal");
        yPos = playerController.GetAxis("MoveVertical");

        transform.Translate(new Vector2(xPos, yPos) * aimSpeed * Time.fixedDeltaTime);

        if (GameManager.instance.IsRacing)
        {
            if (playerController.GetButton("AButton") && canThrowCoconut)
            {
                ThrowCoconut();
                Hud.instance.cocoFills[player.playerId].gameObject.SetActive(true);
                Hud.instance.cocoFills[player.playerId].fillAmount = 0;
            }

            //if (playerController.GetButton("BButton"))
            //{
            //    Debug.LogError("B !!!");
            //    GameManager.instance.OctoHorses[0].canBreathAgain = true;
            //    GameManager.instance.OctoHorses[0].ActiveSecondBreath();
            //}
        }
    }
 private void toggleConfirmation(Image check, Rewired.Player gamePadController, bool ready = false)
 {
     if (ready)
     {
         Color tempColor = check.color;
         tempColor.a = 1f;
         check.color = tempColor;
     }
     else
     {
         if (gamePadController.GetButton("Jump"))
         {
             Color tempColor = check.color;
             tempColor.a = 1f;
             check.color = tempColor;
         }
         else
         {
             Color tempColor = check.color;
             tempColor.a = checkTransparency;
             check.color = tempColor;
         }
     }
 }
Ejemplo n.º 19
0
    private void FixedUpdate()
    {
        // Default actions.
        if (playerInput.GetButton("Jump"))
        {
            movement.JumpHold();
        }
        else
        {
            movement.TryJumpRelease();
        }

        if (playerInput.GetButton("Accelerate"))
        {
            movement.DebugMove();
        }

        if (playerInput.GetButtonDown("Flip Over"))
        {
            movement.FlipOver();
        }

        // Switch control scheme
        if (playerInput.GetButton("Set Controls 1"))
        {
            controlMode = ControlMode.SkidAndCarve;
        }
        else if (playerInput.GetButton("Set Controls 2"))
        {
            controlMode = ControlMode.FrontBack;
        }
        else if (playerInput.GetButton("Set Controls 3"))
        {
            controlMode = ControlMode.TurnAndLean;
        }
        else if (playerInput.GetButton("Set Controls 4"))
        {
            controlMode = ControlMode.FrontBackLocal;
        }

        Vector3 leftStickInputSpace  = new Vector3(playerInput.GetAxis("Left Stick Horizontal"), 0.0f, playerInput.GetAxis("Left Stick Vertical"));
        Vector3 rightStickInputSpace = new Vector3(playerInput.GetAxis("Right Stick Horizontal"), 0.0f, playerInput.GetAxis("Right Stick Vertical"));

        switch (controlMode)
        {
        case ControlMode.BasicSteer:
            UpdateBasicSteer(leftStickInputSpace, rightStickInputSpace);
            break;

        case ControlMode.SkidAndCarve:
            UpdateSkidAndCarve(leftStickInputSpace, rightStickInputSpace);
            break;

        case ControlMode.SlalomAndCarve:
            UpdateSlalomAndCarve(leftStickInputSpace, rightStickInputSpace);
            break;

        case ControlMode.TurnAndLean:
            UpdateTurnAndLean(leftStickInputSpace, rightStickInputSpace);
            break;

        case ControlMode.Warthog:
            UpdateWarthog(leftStickInputSpace, rightStickInputSpace);
            break;

        case ControlMode.FrontBack:
            UpdateFrontBackSteering(leftStickInputSpace, rightStickInputSpace);
            break;

        case ControlMode.FrontBackLocal:
            UpdateFrontBackSteering(leftStickInputSpace, rightStickInputSpace, false);
            break;
        }
    }
Ejemplo n.º 20
0
 public bool GetButton(string button)
 {
     return(player.GetButton(button));
 }
Ejemplo n.º 21
0
    public void Update()
    {
        // make sure we never exceed our mag size
        if (mag > magSize)
        {
            mag = magSize;
        }

        // set our weapons to active or inactive
        // blaster
        if (player.activeWeapon == PlayerController.Weapons.Blaster)
        {
            if (player.blaster.activeSelf == false)
            {
                player.blaster.SetActive(true);
                magSize        = 10;
                myInfo.magSize = magSize;
                fireRate       = 0.2f;
                dmg            = 7;
                //player.blasterCrosshairs.SetActive(true);
            }
        }
        else
        {
            player.blaster.SetActive(false);
            //player.blasterCrosshairs.SetActive(false);
        }

        // grenade launcher
        if (player.activeWeapon == PlayerController.Weapons.Grenade)
        {
            if (player.grenadeLauncher.activeSelf == false)
            {
                player.grenadeLauncher.SetActive(true);
                magSize        = 6;
                myInfo.magSize = magSize;
                fireRate       = 0.5f;
                dmg            = 20;
                //player.grenadeCrosshairs.SetActive(true);
            }
        }
        else
        {
            player.grenadeLauncher.SetActive(false);
            //player.grenadeCrosshairs.SetActive(false);
        }

        // machine
        if (player.activeWeapon == PlayerController.Weapons.Machine)
        {
            if (player.machineGun.activeSelf == false)
            {
                player.machineGun.SetActive(true);
                magSize        = 20;
                myInfo.magSize = magSize;
                fireRate       = 0.1f;
                dmg            = 10;
                //player.machineCrosshairs.SetActive(true);
            }
        }
        else
        {
            player.machineGun.SetActive(false);
            //player.machineCrosshairs.SetActive(false);
        }

        // missile
        if (player.activeWeapon == PlayerController.Weapons.Missile)
        {
            if (player.missileLauncher.activeSelf == false)
            {
                player.missileLauncher.SetActive(true);
                magSize        = 5;
                myInfo.magSize = magSize;
                fireRate       = 1f;
                dmg            = 30;
                //player.missileCrosshairs.SetActive(true);
            }
        }
        else
        {
            player.missileLauncher.SetActive(false);
            //player.missileCrosshairs.SetActive(false);
        }

        // shotgun
        if (player.activeWeapon == PlayerController.Weapons.Shotgun)
        {
            if (player.shotgunGun.activeSelf == false)
            {
                player.shotgunGun.SetActive(true);
                magSize        = 5;
                myInfo.magSize = magSize;
                fireRate       = 1f;
                dmg            = 5;
                //player.shotgunCrosshairs.SetActive(true);
            }
        }
        else
        {
            player.shotgunGun.SetActive(false);
            //player.shotgunCrosshairs.SetActive(false);
        }

        // sniper
        if (player.activeWeapon == PlayerController.Weapons.Sniper)
        {
            if (player.sniperRifle.activeSelf == false)
            {
                player.sniperRifle.SetActive(true);
                magSize        = 1;
                myInfo.magSize = magSize;
                fireRate       = 1f;
                dmg            = 40;
                //player.sniperCrosshairs.SetActive(true);
            }
        }
        else
        {
            player.sniperRifle.SetActive(false);
            //player.sniperCrosshairs.SetActive(false);
        }

        // Check if the player has pressed the fire button and if enough time has elapsed since they last fired
        if ((rewiredPlayer.GetAxis("FireTrigger") > 0.1f || Input.GetMouseButtonDown(0)) && Time.time > nextFire)
        {
            #region

            if (mag > 0)
            {
                mag--;
                myInfo.updateAmmo(mag);

                // Update the time when our player can fire next
                nextFire = Time.time + fireRate;

                player.weaponAnim.Play("fireR");
                int x = modApp.ScatterCheck();

                // blaster
                if (player.activeWeapon == PlayerController.Weapons.Blaster)
                {
                    for (int i = 0; i < x; i++)
                    {
                        shootProjectile(player.blasterShotRotAdd, player.blasterEnd, player.blasterProjectile, player.blasterShotSpeed);
                    }
                }

                // grenade launcher
                if (player.activeWeapon == PlayerController.Weapons.Grenade)
                {
                    for (int i = 0; i < x; i++)
                    {
                        shootProjectile(player.grenadeShotRotAdd, player.grenadeLauncherEnd, player.grenadeProjectile, player.grenadeShotSpeed);
                    }
                }

                // machine gun
                if (player.activeWeapon == PlayerController.Weapons.Machine)
                {
                    for (int i = 0; i < x; i++)
                    {
                        shootProjectile(player.machineShotRotAdd, player.machineGunEnd, player.machineProjectile, player.machineShotSpeed);
                    }
                }

                // missile launcher
                if (player.activeWeapon == PlayerController.Weapons.Missile)
                {
                    for (int i = 0; i < x; i++)
                    {
                        shootProjectile(player.missileShotRotAdd, player.missileLauncherEnd, player.missileProjectile, player.missileShotSpeed);
                    }
                }

                // shotgun
                if (player.activeWeapon == PlayerController.Weapons.Shotgun)
                {
                    for (int i = 0; i < x; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            shootProjectile(player.shotgunShotRotAdd, player.shotgunEnd, player.shotgunProjectile, player.shotgunShotSpeed);
                        }
                    }
                }

                // sniper
                if (player.activeWeapon == PlayerController.Weapons.Sniper)
                {
                    for (int i = 0; i < x; i++)
                    {
                        shootProjectile(player.sniperShotRotAdd, player.sniperRifleEnd, player.sniperProjectile, player.sniperShotSpeed);
                    }
                }
            }

            #region
            //player.muzzle.Play();

            // Start our ShotEffect coroutine to turn our laser line on and off
            //player.StartCoroutine(ShotEffect());

            // Create a vector at the center of our camera's viewport
            //Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

            // Declare a raycast hit to store information about what our raycast has hit
            //RaycastHit hit;

            // Set the start position for our visual effect for our laser to the position of gunEnd
            //laserLine.SetPosition(0, player.gunEnd.position);

            // Check if our raycast has hit anything

            /*
             *          if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
             *          {
             *                  // Set the end position for our laser line
             *                  laserLine.SetPosition(1, hit.point);
             *
             *                  if (hit.collider.gameObject.CompareTag("Player"))
             *                  {
             *                          player.InstantiateBlood(hit.point);
             *      hit.collider.gameObject.GetComponent<InfoTracker>().TakeDamage(dmg);
             *      modApp.VampCheck();
             *  }
             *  else if (hit.collider.gameObject.CompareTag("Breakable"))
             *  {
             *      hit.collider.gameObject.GetComponent<BreakableObject>().TakeDamage();
             *      player.InstantiateBurst(hit.point);
             *  }
             *  else
             *  {
             *      player.InstantiateBurst(hit.point);
             *  }
             *          }
             *          else
             *          {
             *                  // If we did not hit anything, set the end of the line to a position directly in front of the camera at the distance of weaponRange
             *                  laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
             *          }
             *  }
             *  else
             *  {
             *          player.StartCoroutine(Reload());
             *  }*/

            #endregion
        }

        #endregion

        if (rewiredPlayer.GetButton("Reload") && mag < magSize)
        {
            mag = 0;
            player.StartCoroutine(Reload());
        }

        if (rewiredPlayer.GetButton("A") && myInfo.rm.isOver)
        {
            SceneManager.LoadScene("GameplayBase");
        }

        if (rewiredPlayer.GetButton("B") && myInfo.rm.isOver)
        {
            SceneManager.LoadScene("Main Menu");
        }
    }
Ejemplo n.º 22
0
    private void Update()
    {
        Rewired.Player rewiredPlayer = Rewired.ReInput.players.GetPlayer(kRewiredPlayerId);

        if (_scaredTimer > 0)
        {
            _scaredTimer -= Time.deltaTime;
            _characterMovement.MoveVector = Vector3.zero;
            _isSneaking = false;
            _characterMovement.MoveSpeedMultiplier  = 0.0f;
            _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.Idle;
            _playerAnimation.CurrentLocomotionSpeed = 0.0f;
        }
        else
        {
            float horizontalAxis = rewiredPlayer.GetAxis(RewiredConsts.Action.MoveHorizontal);
            float verticalAxis   = rewiredPlayer.GetAxis(RewiredConsts.Action.MoveVertical);

            Vector3 horizontalVector = Camera.main.transform.right.WithY(0).normalized *horizontalAxis;
            Vector3 verticalVector   = Camera.main.transform.forward.WithY(0).normalized *verticalAxis;

            _characterMovement.MoveVector = horizontalVector + verticalVector;

            _isSneaking = rewiredPlayer.GetButton(RewiredConsts.Action.Sneak);
            _characterMovement.MoveSpeedMultiplier = _isSneaking ? 0.5f : 1.0f;

            if (_objectHolder.IsHoldingObject)
            {
                _characterMovement.MoveSpeedMultiplier *= 0.8f;
            }

            if (_characterMovement.CurrentVelocity.magnitude > 0.01f)
            {
                if (_isSneaking)
                {
                    if (_objectHolder.IsHoldingObject)
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.SneakCarry;
                    }
                    else
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.Sneak;
                    }
                }
                else
                {
                    if (_objectHolder.IsHoldingObject)
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.JogCarry;
                    }
                    else
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.Jog;
                    }
                }

                _playerAnimation.CurrentLocomotionSpeed = _characterMovement.CurrentVelocity.magnitude;
            }
            else
            {
                if (_isSneaking)
                {
                    _playerAnimation.CurrentLocomotionSpeed = 0;
                    if (_objectHolder.IsHoldingObject)
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.SneakCarry;
                    }
                    else
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.Sneak;
                    }
                }
                else
                {
                    _playerAnimation.CurrentLocomotionSpeed = 1;
                    if (_objectHolder.IsHoldingObject)
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.IdleCarry;
                    }
                    else
                    {
                        _playerAnimation.CurrentLocomotionState = PlayerAnimatorController.LocomotionState.Idle;
                    }
                }
            }

            // Contextual interact
            if (rewiredPlayer.GetButtonDown(RewiredConsts.Action.Interact))
            {
                // Interact with something
                if (_interactionController.ClosestInteractable != null)
                {
                    Interactable interactable = _interactionController.ClosestInteractable;
                    interactable.TriggerInteraction();
                    InteractWithObject(interactable);
                }
                // Drop or throw a held object
                else if (_objectHolder.HeldObject != null)
                {
                    HoldableObject heldObject = _objectHolder.HeldObject;
                    _objectHolder.DropObject();
                    if (_characterMovement.CurrentVelocity.magnitude > 0.5f)
                    {
                        Vector3 throwForce = (_characterMovement.CurrentVelocity + Vector3.up * 3) * 3;
                        heldObject.Rigidbody.AddForce(throwForce, ForceMode.VelocityChange);
                        heldObject.gameObject.AddComponent <SanityRestoreInWater>();
                    }
                }
            }

            // Scream into or uncork a held bottle
            if (rewiredPlayer.GetButtonDown(RewiredConsts.Action.Scream))
            {
                if (_objectHolder.IsHoldingObject)
                {
                    ReleaseBottleScream();
                }
            }
        }
    }
Ejemplo n.º 23
0
        bool actorInput()
        {
            //
            MouseDataSingleton mouseSingleton = default;

            updateMouse(ref mouseSingleton);


            //
            var myPlayerSingleton = GetSingleton <MyPlayerSingleton>();
            var myPlayerEntity    = myPlayerSingleton.playerEntity;

            if (myPlayerEntity == Entity.Null)
            {
                return(false);
            }
            if (EntityManager.HasComponent <PlayerActorArray>(myPlayerEntity) == false)
            {
                return(false);
            }
            var actors = EntityManager.GetComponentData <PlayerActorArray>(myPlayerEntity);

            if (actors.shipEntity == Entity.Null)
            {
                return(false);
            }

            if (EntityManager.HasComponent <ShipControlInfo>(actors.shipEntity) == false)
            {
                var actor       = EntityManager.GetComponentData <Actor>(actors.shipEntity);
                var shipSpawner = actorSpawnerMap.GetActorSpawner(actor.actorType) as ShipSpawner;
                shipSpawner.AddComponentTypesInMyShip(actors.shipEntity);
            }


            //if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() == false)
            {
                float3     shipPosition = EntityManager.GetComponentData <Translation>(actors.shipEntity).Value;
                quaternion shipRotation = EntityManager.GetComponentData <Rotation>(actors.shipEntity).Value;


                //
                var observerSingleton = GetSingleton <ObserverSingleton>();
                {
                    observerSingleton.position = (half2)math.lerp(shipPosition, mouseSingleton.point, 0.5f).xz;
                }
                SetSingleton(observerSingleton);


                //
                Entities
                .WithAll <NetworkUnreliableOutBuffer>().WithAllReadOnly <NetworkConnection>()
                .WithNone <NetworkDisconnectedMessage>()
                .ForEach((DynamicBuffer <NetworkUnreliableOutBuffer> outBuffer) =>
                {
                    //
                    if (EntityManager.HasComponent <ShipLostInputState>(actors.shipEntity) == false)
                    {
                        var torqueY = 0f;     //[0,1]
                        if (input.GetButton(PlayerInputActions.Torque))
                        {
                            var angle = Vector3.SignedAngle(math.forward(shipRotation), mouseSingleton.direction, Vector3.up);
                            angle     = Mathf.Clamp(angle, -maxAngle, maxAngle);
                            torqueY   = math.pow(angle / maxAngle, 2f);
                            if (angle < 0f)
                            {
                                torqueY = -torqueY;
                            }
                        }
                        else
                        {
                            torqueY = input.GetButton(PlayerInputActions.Torque_Left) ? -1f : input.GetButton(PlayerInputActions.Torque_Right) ? 1f : 0f;
                        }


                        var move = input.GetAxis2D(PlayerInputActions.Move_Horizontal, PlayerInputActions.Move_Vertical);
                        var s    = new PlayerActorMoveInputSerialize
                        {
                            observerPosition = observerSingleton.position,
                            shipMoveInput    = new ShipMoveInput
                            {
                                moveForward = move.y > 0f,
                                moveBack    = move.y < 0f,
                                moveLeft    = move.x <0f,
                                                      moveRight = move.x> 0f,

                                torqueY = (half)torqueY,

                                accelerate = input.GetButton(PlayerInputActions.Accelerate),
                            }
                        };

                        if (math.distance(s.observerPosition, lastShipMoveInput.observerPosition) > 10f ||
                            s.shipMoveInput.moveForward != lastShipMoveInput.shipMoveInput.moveForward ||
                            s.shipMoveInput.moveBack != lastShipMoveInput.shipMoveInput.moveBack ||
                            s.shipMoveInput.moveLeft != lastShipMoveInput.shipMoveInput.moveLeft ||
                            s.shipMoveInput.moveRight != lastShipMoveInput.shipMoveInput.moveRight ||
                            s.shipMoveInput.torqueY != lastShipMoveInput.shipMoveInput.torqueY ||
                            s.shipMoveInput.accelerate != lastShipMoveInput.shipMoveInput.accelerate)
                        {
                            s._DoSerialize(outBuffer);

                            lastShipMoveInput = s;
                            EntityManager.SetComponentData(actors.shipEntity, s.shipMoveInput);
                        }
                    }


                    //
                    if (EntityManager.HasComponent <ShipLostInputState>(actors.shipEntity) == false)
                    {
                        //
                        FireAction fireAction = FireAction.none;
                        for (var i = PlayerInputActions.Weapon0; i <= PlayerInputActions.Weapon6; ++i)
                        {
                            if (input.GetButtonDown(i))
                            {
                                var index = i - PlayerInputActions.Weapon0;
                                if (input.GetButton(PlayerInputActions.Shift))
                                {
                                    fireAction = (FireAction)index + (int)FireAction.__uninstallSlotIndexBegin;
                                }
                                else
                                {
                                    fireAction = (FireAction)index + (int)FireAction.__fireSlotIndexBegin;
                                }
                                break;
                            }
                        }


                        if (fireAction == FireAction.none)
                        {
                            for (var i = PlayerInputActions.AssistWeapon0; i <= PlayerInputActions.AssistWeapon2; ++i)
                            {
                                if (input.GetButtonDown(i))
                                {
                                    var index = i - PlayerInputActions.AssistWeapon0;
                                    if (input.GetButton(PlayerInputActions.Shift))
                                    {
                                        fireAction = (FireAction)index + (int)FireAction.__uninstallAssistSlotIndexBegin;
                                    }
                                    else
                                    {
                                        //fireAction = (FireAction)index + (int)FireAction.__fireSlotIndexBegin;
                                    }
                                    break;
                                }
                            }
                        }


                        //
                        if (fireAction == FireAction.none)
                        {
                            if (input.GetButtonDown(PlayerInputActions.MouseButton2))
                            {
                                fireAction = FireAction.autoFire;
                            }
                            else if (input.GetButtonDown(PlayerInputActions.MouseButton1))
                            {
                                fireAction = FireAction.mainFire;
                            }

                            /*else if (input.GetButtonDown(PlayerInputActions.MouseButton2))
                             * {
                             *  fireAction = FireAction.mouseButton2;
                             * }*/
                            else if (input.GetButtonDown(PlayerInputActions.Shield))
                            {
                                fireAction = FireAction.shield;
                            }
                        }



                        if (fireAction != FireAction.none)
                        {
                            //
                            var s = new PlayerActorFireInputSerialize
                            {
                                firePosition = (half2)mouseSingleton.point.xz,

                                fireAction = fireAction,
                            };
                            s._DoSerialize(outBuffer);


                            //
                            mouseFx.OnPlayFx(mouseSingleton.point);
                        }
                    }
                });
            }

            return(true);
        }
Ejemplo n.º 24
0
        public void UpdateKeyboard()
        {
            if (StopInput)
            {
                Direction = Vector2.zero;

                Jump   = false;
                Sprint = false;

                DodgeLeft  = false;
                DodgeRight = false;

                return;
            }

            // We get our horizontal/vertical inputs as integers so we don't have to deal with floating point value errors
            Direction.x = (int)(Sprint ? 0 : Inputs.GetAxis("Horizontal"));
            Direction.y = (int)(Sprint ? 1 : Inputs.GetAxis("Vertical"));

            Jump     = Inputs.GetButtonDown("Jump");
            HoldJump = Inputs.GetButton("Jump");

            if (Inputs.GetButtonDoublePressDown("Vertical"))
            {
                Sprint = true;
            }
            else if (Inputs.GetButtonUp("Vertical") || Jump || AnyAttack)
            {
                Sprint = false;
            }

            // Reset the dodge bools before we use it
            DodgeLeft  = false;
            DodgeRight = false;
            if (Settings.GameSettingsManager.Instance.ControlSettings.Save.ControlDoubleTapDodge != 0)
            {
                DodgeLeft  = Inputs.GetNegativeButtonDoublePressDown("Horizontal") && !DodgeRight;
                DodgeRight = Inputs.GetButtonDoublePressDown("Horizontal") && !DodgeLeft;
            }
            else
            {
                DodgeLeft  = Direction.x < 0 && Direction.y == 0 && Jump && !DodgeRight;
                DodgeRight = Direction.x > 0 && Direction.y == 0 && Jump && !DodgeLeft;
            }

            if (Inputs.GetButtonDown("Camera Side"))
            {
                CameraSide = !CameraSide;
            }

            // Select Weapon
            if (Inputs.GetButtonDown("Weapon 1"))
            {
                WeaponNumber = 0;
            }
            if (Inputs.GetButtonDown("Weapon 2"))
            {
                WeaponNumber = 1;
            }
            if (Inputs.GetButtonDown("Weapon 3"))
            {
                WeaponNumber = 2;
            }

            // Scroll Weapon
            if (Inputs.GetAxis("Scroll Weapon") * MouseScrollSpeed >= 1)
            {
                WeaponNumber--;
            }
            else if (Inputs.GetAxis("Scroll Weapon") * MouseScrollSpeed <= -1)
            {
                WeaponNumber++;
            }
            // Infinite scroll allows us to go to the first weapon if we attempt to scroll down on the last weapon
            if (Settings.GameSettingsManager.Instance.ControlSettings.Save.ControlWeaponSwitchInfiniteScroll != 0)
            {
                // Just reset the number
                WeaponNumber = WeaponNumber > 2 ? 0 : WeaponNumber < 0 ? 2 : WeaponNumber;
            }

            WeaponNumber = Mathf.Clamp(WeaponNumber, 0, 2);
        }