예제 #1
0
    private static void UpdateJumpKeep(ref PlayerStates states, ref MovementData movementData,
                                       PlayerMovementAbilityData movementAbilityData,
                                       PlayerInputData inputData, float deltaTime)
    {
        if (states.JumpKeepTime <= 0)
        {
            return;
        }

        if (!inputData.LastFrameJumpHit && !inputData.LastFrameJumpKeep ||
            !inputData.JumpKeep)
        {
            states.JumpKeepTime = 0;
            return;
        }

        states.JumpKeepTime -= deltaTime;
        var vel = movementData.Velocity;

        vel.y = movementAbilityData.JumpHitSpeed;
        movementData.Velocity = vel;

        if (states.JumpKeepTime < 0)
        {
            states.JumpKeepTime = 0;
        }
    }
예제 #2
0
        public bool Behave(Entity entity, EntityManager dstManager, ref PlayerInputData inputData)
        {
            if (_path.status == NavMeshPathStatus.PathInvalid || _transform == null)
            {
                return(false);
            }

            var distSq = math.distancesq(_transform.position, _path.corners[_currentWaypoint]);

            if (distSq <= Constants.WAYPOINT_SQDIST_THRESH)
            {
                _currentWaypoint++;
            }

            if ((_currentWaypoint == _path.corners.Length - 1 && distSq < FINISH_ROAM_DISTSQ) || _currentWaypoint >= _path.corners.Length)
            {
                inputData.Move = float2.zero;
                return(false);
            }

            var dir = math.normalize(_path.corners[_currentWaypoint] - _transform.position);

            inputData.Move = new float2(dir.x, dir.z);

            return(true);
        }
예제 #3
0
    public void SendInput(string command)
    {
        PlayerInputData data = new PlayerInputData();

        data.command = command;
        socket.Emit("playerInput", JsonUtility.ToJson(data));
    }
예제 #4
0
    public void PerformUpdate(int index)
    {
        if (inputs.Length > 0)
        {
            PlayerInputData input = inputs.First();
            InputTick++;

            for (int i = 1; i < inputs.Length; i++)
            {
                InputTick++;
                for (int j = 0; j < input.Keyinputs.Length; j++)
                {
                    input.Keyinputs[j] = input.Keyinputs[j] || inputs[i].Keyinputs[j];
                }
                input.LookDirection = inputs[i].LookDirection;
            }

            CurrentUpdateData = Logic.GetNextFrameData(input, CurrentUpdateData);
        }



        UpdateDataHistory.Add(CurrentUpdateData);
        if (UpdateDataHistory.Count > 10)
        {
            UpdateDataHistory.RemoveAt(0);
        }

        transform.localPosition = CurrentUpdateData.Position;
        transform.localRotation = CurrentUpdateData.LookDirection;
        Room.UpdateDatas[index] = CurrentUpdateData;
    }
예제 #5
0
    public PlayerStateData PlayerUpdate()
    {
        if (inputs.Length > 0)
        {
            PlayerInputData input = inputs.First();
            InputTick++;

            for (int i = 1; i < inputs.Length; i++)
            {
                InputTick++;
                for (int j = 0; j < input.Keyinputs.Length; j++)
                {
                    input.Keyinputs[j] = input.Keyinputs[j] || inputs[i].Keyinputs[j];
                }
                input.LookDirection = inputs[i].LookDirection;
            }

            currentPlayerStateData = PlayerLogic.GetNextFrameData(input, currentPlayerStateData);
        }

        PlayerStateDataHistory.Add(currentPlayerStateData);
        if (PlayerStateDataHistory.Count > 10)
        {
            PlayerStateDataHistory.RemoveAt(0);
        }

        transform.localPosition = currentPlayerStateData.Position;
        transform.localRotation = currentPlayerStateData.LookDirection;
        return(currentPlayerStateData);
    }
 private void HandleInputOnce(PlayerInputData inputData)
 {
     if (inputData.inputTokens[6]) // Jump
     {
         inputData.EatInputToken(6);
         if (AdvancedMovement.CanStand(movementController)) // If can stand
         {
             if (!movementController.IsAirborne())
             {
                 stateMachine.ChangeState(playerController.jumpingState);
             }
         }
     }
     else if (inputData.inputTokens[3]) // Crouch
     {
         inputData.EatInputToken(3);
         if (!movementController.IsAirborne())
         {
             stateMachine.ChangeState(playerController.crouchingState);
         }
         else
         {
             stateMachine.ChangeState(playerController.fallingState);
         }
     }
 }
예제 #7
0
    private static MovementData UpdateHorizontal(ref MovementData movementData, PlayerInputData inputData, PlayerMovementAbilityData movementAbilityData,
                                                 float deltaTime, PlayerStates states)
    {
        var vel = movementData.Velocity;

        var maxHorizontalSpeed = inputData.FireKeep ? movementAbilityData.MaxHorizontalSpeedDashing : movementAbilityData.MaxHorizontalSpeed;
        var horizontalAcc      = inputData.FireKeep ? movementAbilityData.HorizontalDashingAcc : movementAbilityData.HorizontalAcc;

        if (inputData.HorizontalInput != 0)
        {
            vel.x = math.clamp(vel.x + inputData.HorizontalInput * horizontalAcc * deltaTime,
                               -maxHorizontalSpeed, maxHorizontalSpeed);
        }
        else if (PlayerUtility.IsGrounded(states))
        {
            var sign           = math.sign(vel.x);
            var value          = math.abs(vel.x);
            var amountToReduce = movementAbilityData.HorizontalReverseAcc * deltaTime;
            value = value < amountToReduce ? 0 : value - amountToReduce;
            vel.x = sign * value;
        }

        movementData.Velocity = vel;
        return(movementData);
    }
예제 #8
0
        public bool Behave(Entity entity, EntityManager dstManager, ref PlayerInputData inputData)
        {
            if (!_abilities.ActionPossible())
            {
                return(false);
            }

            if (Physics.Raycast(_transform.position + VIEW_POINT_DELTA, _target.position - _transform.position, out var hit,
                                AIM_MAX_DIST) && hit.transform == _target)
            {
                var dir   = _target.position - _transform.position;
                var angle = Vector2.Angle(new Vector2(dir.x, dir.z),
                                          new Vector2(_transform.forward.x, _transform.forward.z));

                if (angle < SHOOTING_ANGLE_THRESH)
                {
                    inputData.CustomInput[_behaviour.executeCustomInput] = 1f;
                }
                else
                {
                    inputData.CustomInput[_behaviour.executeCustomInput] = 0f;
                }

                inputData.Move = math.normalize(new float2(dir.x, dir.z));

                return(true);
            }

            return(false);
        }
예제 #9
0
 private void HandleInputOnce(PlayerInputData inputData)
 {
     if (inputData.inputTokens[8]) // Light
     {
         inputData.EatInputToken(8);
         if (playerController.playerCharacterData.GetPrimaryWeapon() != WeaponType.NONE)
         {
             stateMachine.ChangeState(playerController.lightActionState);
         }
     }
     else if (inputData.inputTokens[9]) // Medium
     {
         inputData.EatInputToken(9);
         if (playerController.playerCharacterData.GetPrimaryWeapon() != WeaponType.NONE)
         {
             stateMachine.ChangeState(playerController.mediumActionState);
         }
     }
     else if (inputData.inputTokens[10]) // Heavy
     {
         inputData.EatInputToken(10);
         if (playerController.playerCharacterData.GetPrimaryWeapon() != WeaponType.NONE)
         {
             stateMachine.ChangeState(playerController.heavyActionState);
         }
     }
 }
    void FixedUpdate()
    {
        bool[] inputs = new bool[6];
        inputs[0] = Input.GetKey(KeyCode.W);
        inputs[1] = Input.GetKey(KeyCode.A);
        inputs[2] = Input.GetKey(KeyCode.S);
        inputs[3] = Input.GetKey(KeyCode.D);
        inputs[4] = Input.GetKey(KeyCode.Space);
        inputs[5] = Input.GetMouseButton(0);

        yaw   += Input.GetAxis("Mouse X") * sensitivityX;
        pitch += Input.GetAxis("Mouse Y") * sensitivityY;

        Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);

        PlayerInputData inputData = new PlayerInputData(inputs, rotation, GameManager.Instance.LastRecievedServerTick - 1);

        transform.position = interpolation.CurrentData.Position;
        PlayerStateData nextStateData = playerLogic.GetNextFrameData(inputData, interpolation.CurrentData);

        interpolation.SetFramePosition(nextStateData);

        using (Message message = Message.Create((ushort)Tags.GamePlayerInput, inputData))
        {
            ConnectionManager.Instance.Client.SendMessage(message, SendMode.Reliable);
        }
    }
예제 #11
0
    void proccessCommand(string playerId, PlayerInputData input)
    {
        Debug.Log("command: " + input.command);

        Player player = GAME_STATE.GetPlayer(playerId);

        Commands playerCommand = Commands.NONE;

        Enum.TryParse(input.command, out playerCommand);

        switch (playerCommand)
        {
        case Commands.UP:
            Debug.Log("Player: " + player.Nickname + " Press UP");
            break;

        case Commands.DOWN:
            Debug.Log("Player: " + player.Nickname + " Press DOWN");
            break;

        case Commands.MOVE:
            Debug.Log("Player: " + player.Nickname + " Axis: " + input);
            player.SetAxis(input.axisHorizontal, input.axisVertical);
            break;

        default:
            Debug.Log("Player: " + player.Nickname + " Press NONE");
            break;
        }
    }
예제 #12
0
    private void HandleInput(bool isArmed, PlayerInputData inputData)
    {
        if (!inputData.pressedInputs[5]) // let go of guard
        {
            stateMachine.ChangeState(playerController.standingState);
        }

        if (isArmed)
        {
            if (playerController.playerInputData.pressedInputs[1]) // right
            {
                BasicMovement.FaceRight(movementController);
            }
            else if (playerController.playerInputData.pressedInputs[2]) // left
            {
                BasicMovement.FaceLeft(movementController);
            }
        }
        else // Not armed
        {
            if (playerController.playerInputData.pressedInputs[1] ||
                playerController.playerInputData.pressedInputs[2]) // right
            {
                stateMachine.ChangeState(playerController.walkingState);
                return;
            }
        }
    }
    private PlayerInputData ReadPlayerInput(PlayerInputData player, string sortString)
    {
        Char[] serialInput = sortString.ToCharArray();

        int LeftIndex  = (player.PlayerNumber - 1) * 2;
        int RightIndex = LeftIndex + 1;

        if (serialInput.Length >= (2 * player.PlayerNumber) && (serialInput[LeftIndex] == '1' && serialInput[RightIndex] == '1'))
        {
            //If the player press both platforms, do nothing!!
        }
        else if (player.bLeftStep && serialInput.Length > LeftIndex && serialInput[LeftIndex] == '1')
        {
            player.playerInput = 1;
            player.bLeftStep   = false;
            Debug.Log("Left Step");
        }
        else if (!player.bLeftStep && serialInput.Length > RightIndex && serialInput[RightIndex] == '1')
        {
            player.playerInput = 1;
            player.bLeftStep   = true;
            Debug.Log("Rigth Step");
        }
        else
        {
            player.playerInput = 0;
        }

        return(player);
    }
예제 #14
0
    /// <summary>
    /// Sets default values for player data that interfaces with the engine, such as the player position
    /// </summary>
    void SetDefaultPlayerData()
    {
        c_trickPhysicsData = new TrickPhysicsData(Attributes.Tricks, Attributes.MaxStats);
        c_positionData     = new PlayerPositionData(transform.position, transform.forward, transform.rotation);
        c_scoringData      = new ScoringData();
        c_inputData        = new PlayerInputData();
        c_stateData        = new StateData();
        c_aerialMoveData   = new AerialMoveData();
        c_entityData       = new EntityData();
        c_collisionData    = new CollisionData(CollisionData.FrontRayOffset, CollisionData.BackRayOffset);
        c_lastFrameData    = new LastFramePositionData();
        c_turnData         = new PlayerHandlingData(c_playerData.f_turnSpeed, c_playerData.f_turnAcceleration, c_playerData.f_turnSpeedDeceleration, c_playerData.f_turnAcceleration * 2, this.Attributes.Balance);

        c_playerData.v_currentPosition               = transform.position;
        c_playerData.q_currentRotation               = transform.rotation;
        c_playerData.q_targetRotation                = transform.rotation;
        c_playerData.v_currentAirDirection           = transform.forward;
        c_playerData.v_currentNormal                 = transform.up;
        c_playerData.v_currentDown                   = transform.up * -1;
        c_playerData.f_currentSpeed                  = Constants.ZERO_F;
        c_playerData.f_currentAcceleration           = c_playerData.f_acceleration;
        c_playerData.f_currentTopSpeed               = c_playerData.f_topSpeed;
        c_playerData.f_currentJumpCharge             = Constants.ZERO_F;
        c_playerData.f_currentForwardRaycastDistance = c_playerData.f_forwardRaycastDistance;
        c_playerData.f_currentRaycastDistance        = c_playerData.f_raycastDistance;
        c_playerData.f_surfaceAngleDifference        = 0.0f;
        c_playerData.b_obstacleInRange               = false;

        c_lastFrameData.v_lastFramePosition = transform.position;
        c_lastFrameData.q_lastFrameRotation = transform.rotation;

        c_stateData.b_updateState    = true;
        c_stateData.b_courseFinished = false;
    }
예제 #15
0
 public static void UpdateInput(GameObject player, PlayerInputData input)
 {
     if (player == null)
     {
         return;
     }
     player.GetComponent <PlayerMovement>().UpdateInput(input);
 }
예제 #16
0
 private void HandleInputOnce(PlayerInputData inputData)
 {
     if (inputData.inputTokens[6]) // Jump
     {
         inputData.EatInputToken(6);
         stateMachine.ChangeState(playerController.slidingJumpState);
     }
 }
예제 #17
0
    private void HandleInputOnce(PlayerInputData inputData)
    {
        WeaponType primaryWeapon = playerController.playerCharacterData.GetPrimaryWeapon();

        if (inputData.inputTokens[8]) // Light
        {
            inputData.EatInputToken(8);
            if (primaryWeapon != WeaponType.NONE)
            {
                stateMachine.ChangeState(playerController.lightActionState);
            }
        }
        else if (inputData.inputTokens[9]) // Medium
        {
            inputData.EatInputToken(9);
            if (primaryWeapon != WeaponType.NONE)
            {
                stateMachine.ChangeState(playerController.mediumActionState);
            }
        }
        else if (inputData.inputTokens[10]) // Heavy
        {
            inputData.EatInputToken(10);
            if (primaryWeapon != WeaponType.NONE)
            {
                stateMachine.ChangeState(playerController.heavyActionState);
            }
        }
        else if (inputData.inputTokens[6]) // Jump
        {
            inputData.EatInputToken(6);
            if (AdvancedMovement.CanStand(movementController)) // If can stand
            {
                IState prevState = stateMachine.PeekPreviousState();
                if (prevState == playerController.crouchingState)
                {
                    // If prev state was crouching, skip airborne check
                    stateMachine.ChangeState(playerController.jumpingState);
                }
                else if (!movementController.IsAirborne())
                {
                    stateMachine.ChangeState(playerController.jumpingState);
                }
            }
        }
        else if (inputData.inputTokens[3]) // Crouch
        {
            inputData.EatInputToken(3);
            if (!movementController.IsAirborne())
            {
                stateMachine.ChangeState(playerController.crouchingState);
            }
            else
            {
                stateMachine.ChangeState(playerController.fallingState);
            }
        }
    }
예제 #18
0
    public void SendInput(string command, Vector2 dir)
    {
        PlayerInputData data = new PlayerInputData();

        data.command        = command;
        data.axisHorizontal = dir.x;
        data.axisVertical   = dir.y;
        socket.Emit("playerInput", JsonUtility.ToJson(data));
    }
예제 #19
0
 // Update is called once per frame
 public void UpdateInput(PlayerInputData input)
 {
     anim.SetBool("Run", input.MoveX != 0 || input.MoveY != 0);
     if (input.MoveX != 0)
     {
         transform.localScale = new Vector3(Mathf.Round(input.MoveX) * Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
     }
     rb.velocity = new Vector2(input.MoveX, input.MoveY).normalized * 10f;
 }
예제 #20
0
    public PlayerStateData GetNextFrameData(PlayerInputData input, PlayerStateData currentStateData)
    {
        bool w     = input.Keyinputs[0];
        bool a     = input.Keyinputs[1];
        bool s     = input.Keyinputs[2];
        bool d     = input.Keyinputs[3];
        bool space = input.Keyinputs[4];

        Vector3 rotation = input.LookDirection.eulerAngles;

        gravity = new Vector3(0, currentStateData.Gravity, 0);

        Vector3 movement = Vector3.zero;

        if (w)
        {
            movement += Vector3.forward;
        }
        if (a)
        {
            movement += Vector3.left;
        }
        if (s)
        {
            movement += Vector3.back;
        }
        if (d)
        {
            movement += Vector3.right;
        }

        movement = Quaternion.Euler(0, rotation.y, 0) * movement; // Move towards the look direction.
        movement.Normalize();
        movement = movement * walkSpeed;

        movement = movement * Time.fixedDeltaTime;
        movement = movement + gravity * Time.fixedDeltaTime;

        // The following code fixes character controller issues from unity. It makes sure that the controller stays connected to the ground by adding a little bit of down movement.
        CharacterController.Move(new Vector3(0, -0.001f, 0));

        if (CharacterController.isGrounded)
        {
            if (space)
            {
                gravity = new Vector3(0, jumpStrength, 0);
            }
        }
        else
        {
            gravity -= new Vector3(0, gravityConstant, 0);
        }

        CharacterController.Move(movement);

        return(new PlayerStateData(currentStateData.Id, gravity.y, transform.localPosition, input.LookDirection));
    }
    void PlayerInput(SocketIOEvent evt)
    {
        Debug.Log("data:" + evt.data);
        PlayerInputData inputData = JsonUtility.FromJson <PlayerInputData>(evt.data);

        string playerId = inputData.playerId;


        onPlayerInput(playerId, inputData);
    }
예제 #22
0
 public CarvingState(ref PlayerData playerData,
                     ref PlayerHandlingData turnDataIn,
                     ref PlayerInputData inputData,
                     ref PlayerPositionData positionData)
 {
     this.c_playerData      = playerData;
     this.c_turnData        = turnDataIn;
     this.c_playerInputData = inputData;
     this.c_positionData    = positionData;
 }
예제 #23
0
 public SlowingState(ref PlayerData playerData,
                     ref CollisionData collisionData,
                     ref PlayerInputData inputData,
                     ref PlayerPositionData positionData)
 {
     this.c_playerData         = playerData;
     this.c_playerInputData    = inputData;
     this.c_playerPositionData = positionData;
     this.c_collisionData      = collisionData;
 }
 public void HandleInput(PlayerInputData inputData)
 {
     if (inputData.pressedInputs[1]) // Turn right
     {
         BasicMovement.FaceRight(movementController);
     }
     else if (inputData.pressedInputs[2]) // Turn left
     {
         BasicMovement.FaceLeft(movementController);
     }
 }
    private void CreatePlayer(InputDevice inputDevice)
    {
        PlayerInputData newPlayerInputData = new PlayerInputData();

        newPlayerInputData.inputDevice = inputDevice;
        newPlayerInputData.keyboard    = inputDevice == null;
        newPlayerInputData.playerGO    = Instantiate(playerPrefab);
        newPlayerInputData.playerGO.GetComponent <BrianPlayerMovement>().SetInputDevice(inputDevice);
        newPlayerInputData.playerGO.GetComponent <BrianPlayerMovement>().SetPlayerIndex(players.Count);
        players.Add(newPlayerInputData);
    }
예제 #26
0
 private void HandleMoveInput(PlayerInputData inputData)
 {
     if (inputData.pressedInputs[1]) // right
     {
         BasicMovement.FaceRight(movementController);
     }
     else if (inputData.pressedInputs[2]) // left
     {
         BasicMovement.FaceLeft(movementController);
     }
 }
예제 #27
0
 public void CopyFrom(PlayerInputData data)
 {
     Type    = data.Type;
     MoveX   = data.MoveX;
     MoveY   = data.MoveY;
     Jump    = data.Jump;
     Light   = data.Light;
     Special = data.Special;
     Grab    = data.Grab;
     Guard   = data.Guard;
 }
    // Unity Events:
    protected override void Awake()
    {
        // Anything needed to be passed into the States need to be done BEFORE base.Awake()
        actionController = GetComponent <PlayerActionController>();
        playerInputData  = GetComponent <PlayerInputData>();
        weapons          = GetComponent <PlayerWeapons>();

        base.Awake();

        // Anything that is NOT used by States can be done after
    }
예제 #29
0
 protected override void OnUpdate()
 {
     Entities.With(query).ForEach(entity =>
     {
         var newInput = new PlayerInputData
         {
             Move = new float2(CrossPlatformInputManager.GetAxisRaw("Horizontal"), CrossPlatformInputManager.GetAxisRaw("Vertical"))
         };
         PostUpdateCommands.SetComponent(entity, newInput);
     });
 }
예제 #30
0
        public bool Behave(Entity entity, EntityManager dstManager, ref PlayerInputData inputData)
        {
            if (!_abilities.ActionPossible())
            {
                return(false);
            }

            inputData.CustomInput[_behaviour.executeCustomInput] = 1f;

            return(true);
        }