예제 #1
0
    public void HandleMovement(ClientControlState clientControlState)
    {
        if (this.lastUpdate == null)
        {
            this.lastUpdate = DateTime.Now;
            return;
        }
        float   timePassed = (DateTime.Now - this.lastUpdate).Milliseconds / 1000f;
        Vector3 forward    = Vector3.ProjectOnPlane(this.playerCameraUp, this.terrainUp).normalized *this.speed * timePassed;
        Vector2 direction  = Vector2.zero;

        if (clientControlState.moveUp)
        {
            direction += new Vector2(forward.x, forward.z);
        }
        if (clientControlState.moveLeft)
        {
            direction += new Vector2(-forward.z, forward.x);
        }
        if (clientControlState.moveDown)
        {
            direction += new Vector2(-forward.x, -forward.z);
        }
        if (clientControlState.moveRight)
        {
            direction += new Vector2(forward.z, -forward.x);
        }
        this.position  += direction;
        this.lastUpdate = DateTime.Now;
    }
예제 #2
0
 void ListenForClientControlState()
 {
     while (true)
     {
         if (this.handler == null)
         {
             break;
         }
         byte[] bytes = new byte[1024];
         this.handler.Receive(bytes);
         var clientControlState = new ClientControlState(bytes);
         character.HandleMovement(clientControlState);
     }
 }
예제 #3
0
 void HandleMovement()
 {
     clientControlState = new ClientControlState();
     if (Input.GetKey("w"))
     {
         clientControlState.moveUp = true;
     }
     if (Input.GetKey("a"))
     {
         clientControlState.moveLeft = true;
     }
     if (Input.GetKey("s"))
     {
         clientControlState.moveDown = true;
     }
     if (Input.GetKey("d"))
     {
         clientControlState.moveRight = true;
     }
     // if (!direction.Equals(Vector3.zero)) model.LookAt(model.position + direction, Vector3.up);
 }