Ejemplo n.º 1
0
    private void Update()
    {
        //Tell the animation controller how much distance the player has travelled since the last frame
        float FrameDistance = Vector3.Distance(transform.position, PreviousFramePosition);

        PreviousFramePosition = transform.position;
        AnimationController.SetFloat("Movement", FrameDistance);


        //Count down the interval timer
        NextUpdate -= Time.deltaTime;

        //Wait until the timer hits zero
        if (NextUpdate <= 0.0f)
        {
            //reset the timer
            NextUpdate = UpdateInterval;
            //If our current position is different to what was last sent to the server, when we need to update them
            if (transform.position != PreviousUpdatePosition)
            {
                //Before we update, remember what position was sent to the server
                PreviousUpdatePosition = transform.position;
                PlayerManagementPacketSender.SendPlayerUpdate(transform.position, transform.rotation);
            }
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        //Execute the correct controller function depending on what mode is currently active
        switch (ControllerState)
        {
        case (PlayerControllerState.FirstPersonMode):
            FirstPersonMode();
            break;

        case (PlayerControllerState.ThirdPersonMode):
            ThirdPersonMode();
            break;
        }

        //Keep the server up to date regarding where our character is positioned in the game world
        NextPositionUpdate -= Time.deltaTime;
        if (NextPositionUpdate <= 0.0f)
        {
            //Reset the timer every 0.25 seconds
            NextPositionUpdate = PositionUpdateInterval;
            //If our position or rotation has changed since the last time we told the server then we need to tell it again
            if (transform.position != PreviousUpdatePosition || transform.rotation != PreviousUpdateRotation)
            {
                //Tell the server our new position value
                if (ConnectionManager.Instance.IsConnected)
                {
                    PlayerManagementPacketSender.SendPlayerUpdate(transform.position, transform.rotation);
                }
                //Now remember what we last told the server our values where
                PreviousUpdatePosition = transform.position;
                PreviousUpdateRotation = transform.rotation;
            }
        }
    }