Exemple #1
0
        public override void ExecuteCommand(Bolt.Command c, bool resetState)
        {
            if (state.Dead)
            {
                return;
            }

            PlayerCommand cmd = (PlayerCommand)c;

            if (resetState)
            {
                _motor.SetState(cmd.Result.position, cmd.Result.velocity, cmd.Result.isGrounded, cmd.Result.jumpFrames);
            }
            else
            {
                var result = _motor.Move(cmd.Input.forward, cmd.Input.backward, cmd.Input.left, cmd.Input.right, cmd.Input.jump, cmd.Input.yaw);

                cmd.Result.position   = result.position;
                cmd.Result.velocity   = result.velocity;
                cmd.Result.jumpFrames = result.jumpFrames;
                cmd.Result.isGrounded = result.isGrounded;

                if (cmd.IsFirstExecution)
                {
                    AnimatePlayer(cmd);
                    state.pitch = cmd.Input.pitch;
                }
            }
        }
        public override void ExecuteCommand(Bolt.Command c, bool resetState)
        {
            if (state.Dead)
            {
                return;
            }

            PlayerCommand cmd = (PlayerCommand)c;

            if (resetState)
            {
                _motor.SetState(cmd.Result.position, cmd.Result.localPosition, cmd.Result.velocity, cmd.Result.isGrounded, cmd.Result.jumpFrames);
            }
            else
            {
                // move and save the resulting state
                var result = _motor.Move(cmd.Input.forward, cmd.Input.backward, cmd.Input.left, cmd.Input.right, cmd.Input.jump, cmd.Input.yaw);

                cmd.Result.localPosition = result.localPosition;
                cmd.Result.position      = result.position;
                cmd.Result.velocity      = result.velocity;
                cmd.Result.jumpFrames    = result.jumpFrames;
                cmd.Result.isGrounded    = result.isGrounded;

                if (cmd.IsFirstExecution)
                {
                    // animation
                    AnimatePlayer(cmd);

                    // set state pitch
                    state.pitch  = cmd.Input.pitch;
                    state.weapon = cmd.Input.weapon;
                    state.Aiming = cmd.Input.aiming;

                    // deal with weapons
                    if (cmd.Input.aiming && cmd.Input.fire)
                    {
                        FireWeapon(cmd);
                    }
                }

                if (entity.isOwner)
                {
                    cmd.Result.Token = new TestToken();
                }
            }
        }
    public override void ExecuteCommand(Bolt.Command command, bool resetState)
    {
        PlayerCommandFPS cmd = (PlayerCommandFPS)command;

        if (resetState)
        {
            //we got a correction from the server, reset (this only runs on the client)
            if (m_player.numRespawnTeleportFrames > 0)
            {
                m_playerMotor.SetStateTeleport(cmd.Result.Position, cmd.Result.Velocity, cmd.Result.IsGrounded, cmd.Result.IsDoubleJumpAvailable, cmd.Result.DashDurationCountdown, cmd.Result.DashCooldownCountdown);
            }
            else
            {
                m_playerMotor.SetState(cmd.Result.Position, cmd.Result.Velocity, cmd.Result.IsGrounded, cmd.Result.IsDoubleJumpAvailable, cmd.Result.DashDurationCountdown, cmd.Result.DashCooldownCountdown);
            }
        }
        else
        {
            //apply movement (this runs on both server and client)
            PlayerMotor.MotorState motorState = m_playerMotor.Move(BoltNetwork.FrameDeltaTime, cmd.Input.Forward, cmd.Input.Backward, cmd.Input.Left, cmd.Input.Right, cmd.Input.Jump, cmd.Input.Dash, cmd.Input.Yaw);

            //copy the motor state to the commands result (this gets sent back to the client)
            cmd.Result.Position              = motorState.position;
            cmd.Result.Velocity              = motorState.velocity;
            cmd.Result.IsGrounded            = motorState.isGrounded;
            cmd.Result.IsDoubleJumpAvailable = motorState.isDoubleJumpAvailable;
            cmd.Result.DashDurationCountdown = motorState.dashDurationCountdown;
            cmd.Result.DashCooldownCountdown = motorState.dashCooldownCountdown;

            if (cmd.IsFirstExecution)
            {
                //check if we're the one controlling this entity
                if (entity.HasControl)
                {
                    if (cmd.Input.Fire)
                    {
                        activeWeapon.FireWeapon(entity);
                    }
                }
            }
        }
    }
Exemple #4
0
    // Executes on both the controller (usually client) and owner (usually server)
    public override void ExecuteCommand(Bolt.Command command, bool resetState)
    {
        PlayerCommand cmd = (PlayerCommand)command;

        if (resetState)
        {
            // There was a correction from the server; reset. This only runs on the client.
            //_motor.SetState (cmd.Result.Position, cmd.Result.Velocity, cmd.Result.IsGrounded, cmd.Result.JumpFrames);
        }
        else
        {
            // apply movement (both server + client)
            PlayerMotor.State motorState = _motor.Move(cmd.Input.Forward, cmd.Input.Backward, cmd.Input.LeftStrafe, cmd.Input.RightStrafe, cmd.Input.Jump, cmd.Input.Yaw, cmd.Input.Pitch);

            // copy motor state to the command's result (client)
            cmd.Result.Position   = motorState.position;
            cmd.Result.Velocity   = motorState.velocity;
            cmd.Result.IsGrounded = motorState.isGrounded;
            cmd.Result.JumpFrames = motorState.jumpFrames;
        }
    }
        public override void ExecuteCommand(Bolt.Command command, bool resetState)
        {
            var cmd = (PlayerCommand)command;

            if (resetState)
            {
                motor.SetState(cmd.Result.Position, cmd.Result.Velocity, cmd.Result.IsGrounded, cmd.Result.JumpFrames);
            }
            else
            {
                PlayerMotor.State Result = motor.Move(cmd.Input.forward, cmd.Input.backward, cmd.Input.left, cmd.Input.right, cmd.Input.jump, cmd.Input.yaw);

                //Send Results
                cmd.Result.Position   = Result.position;
                cmd.Result.Velocity   = Result.velocity;
                cmd.Result.JumpFrames = Result.jumpFrames;
                cmd.Result.IsGrounded = Result.isGrounded;

                if (cmd.IsFirstExecution)
                {
                    base.Camera.transform.localEulerAngles = new Vector3(cmd.Input.pitch, 0, 0);
                }
            }
        }
    public override void ExecuteCommand(Bolt.Command c, bool resetState)
    {
        TPCCommand cmd = (TPCCommand)c;

        if (resetState)
        {
            _motor.SetState(cmd.Result.position, cmd.Result.velocity, cmd.Result.isGrounded, cmd.Result.jumpFrames);

            //transform.localPosition = cmd.Result.position;
            //_cc.Move(cmd.Result.velocity);
            //_velocity = cmd.Input.move;
            //_motor.SetState(cmd.Result.position, cmd.Result.velocity, cmd.Result.isGrounded, cmd.Result.jumpFrames);
        }
        else
        {
            var result = _motor.Move(cmd.Input.crouch, cmd.Input.forward, cmd.Input.jump, cmd.Input.move, cmd.Input.turn);

            cmd.Result.position   = result.position;
            cmd.Result.velocity   = result.velocity;
            cmd.Result.jumpFrames = result.jumpFrames;
            cmd.Result.isGrounded = result.isGrounded;

            m_Animator.SetFloat("Forward", cmd.Input.forward, 0f, Time.deltaTime);
            m_Animator.SetFloat("Turn", cmd.Input.turn, 0f, Time.deltaTime);
            m_Animator.SetBool("Crouch", cmd.Input.crouch);
            m_Animator.SetBool("OnGround", cmd.Result.isGrounded);

            if (entity.IsOwner)
            {
                state.forward  = m_Animator.GetFloat("Forward");
                state.turn     = m_Animator.GetFloat("Turn");
                state.crouch   = m_Animator.GetBool("Crouch");
                state.grounded = m_Animator.GetBool("OnGround");
            }

            /*
             *
             * Vector3 move = cmd.Input.move;
             * if (move.magnitude > 1f)
             * move.Normalize();
             * move = transform.InverseTransformDirection(move);
             *
             * move = Vector3.ProjectOnPlane(move, m_GroundNormal);
             *
             * m_TurnAmount = Mathf.Atan2(move.x, move.z);
             * m_ForwardAmount = move.z;
             *
             * m_IsGrounded = _cc.Move(cmd.Input.move * BoltNetwork.frameDeltaTime) == CollisionFlags.Below;
             * m_IsGrounded = m_IsGrounded || _cc.isGrounded;
             * m_IsGrounded = m_IsGrounded || Physics.CheckSphere(sphere, _cc.radius, layerMask);
             * Debug.Log(m_IsGrounded);
             *
             * Vector3 _vel = cmd.Input.move;
             * if (m_IsGrounded == false)
             * _vel.y -= 0.1f;
             * else if(cmd.Input.jump == true)
             * _vel.y += 100f;
             *
             * _cc.Move(_vel);
             *
             * //_velocity = cmd.Input.move;
             * //_cc.Move(cmd.Input.move);
             *
             * float turnSpeed = Mathf.Lerp(180, 360, m_ForwardAmount);
             * transform.Rotate(0, m_TurnAmount * turnSpeed * Time.deltaTime, 0);
             *
             * m_Animator.SetFloat("Forward", cmd.Input.Forward, 0.1f, Time.deltaTime);
             * m_Animator.SetFloat("Turn", cmd.Input.Turn, 0.1f, Time.deltaTime);
             * m_Animator.SetBool("Crouch", cmd.Input.crouch);
             *
             * if (entity.isOwner)
             * {
             * state.Forward = m_Animator.GetFloat("Forward");
             * state.Turn = m_Animator.GetFloat("Turn");
             * state.Crouch = m_Animator.GetBool("Crouch");
             * }
             *
             * cmd.Result.position = transform.localPosition;
             * cmd.Result.velocity = (_cc.velocity);
             *
             */
        }
    }