Пример #1
0
 // Initialisation
 void Start()
 {
     forwardKey.text        = KeyBoardBindings.GetForwardKey().ToString();
     backwardKey.text       = KeyBoardBindings.GetBackwardKey().ToString();
     attackKey.text         = KeyBoardBindings.GetAttackKey().ToString();
     chargedAttackKey.text  = KeyBoardBindings.GetChargedAttackKey().ToString();
     pauseKey.text          = KeyBoardBindings.GetPauseKey().ToString();
     zoomInKey.text         = KeyBoardBindings.GetZoomInKey().ToString();
     zoomOutKey.text        = KeyBoardBindings.GetZoomOutKey().ToString();
     showScoreboardKey.text = KeyBoardBindings.GetScoreboardKey().ToString();
 }
Пример #2
0
    // Update is called once per frame
    //[Client]
    void Update()
    {
        if (isLocalPlayer)
        {
            // Checks for overlay active done in Player.cs

            //float horizontal = Input.GetAxis("Horizontal") * turningSpeed * Time.deltaTime;
            //transform.Rotate(0, horizontal, 0);

            //float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
            //transform.Translate(0, 0, vertical);

            //transform.Translate(movementSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, movementSpeed * Input.GetAxis("Vertical") * Time.deltaTime);


            //float inputX = Input.GetAxis("Horizontal");
            //float inputZ = Input.GetAxis("Vertical");
            //
            //float moveX = inputX * movementSpeed * Time.deltaTime;
            //float moveZ = inputZ * movementSpeed * Time.deltaTime;
            //
            //transform.Translate(moveX, 0f, moveZ);

            //rbody.AddForce(moveX, 0f, moveZ);

            // Rotation & Angles
            UpdatePitch();
            UpdateYaw();    // roll updates here too

            // update player's Euler angles
            //this.transform.eulerAngles = new Vector3(-pitch, yaw, -yaw * 0.5f);
            this.transform.eulerAngles = new Vector3(-pitch, yaw, roll);

            Quaternion rotation = Quaternion.Euler(-pitch, yaw, 0f);
            SetView(rotation * new Vector3(0, 0, 1));

            // SLOWLY PITCH BACK
            if (this.pitch != 0)
            {
                if (this.pitch < 0)
                {
                    this.pitch += changeSpeed * Time.deltaTime;
                    if (this.pitch > 0)
                    {
                        this.pitch = 0;
                    }
                }
                else
                {
                    this.pitch -= changeSpeed * Time.deltaTime;
                    if (this.pitch < 0)
                    {
                        this.pitch = 0;
                    }
                }
            }

            // SLOWLY ROLL BACK
            if (this.roll != 0)
            {
                if (this.roll < 0)
                {
                    this.roll += changeSpeed * Time.deltaTime;
                    if (this.roll > 0)
                    {
                        this.roll = 0;
                    }
                }
                else
                {
                    this.roll -= changeSpeed * Time.deltaTime;
                    if (this.roll < 0)
                    {
                        this.roll = 0;
                    }
                }
            }

            // Movement
            force = Vector3.zero;

#if UNITY_ANDROID
            // get joystick movement
            force         = joystick.GetJoystickDelta() * 100f * view;
            keyNotPressed = false;
#else
            if (Input.GetKey(KeyBoardBindings.GetForwardKey()))
            {
                force         = 100f * view;
                keyNotPressed = false;
            }
            else if (Input.GetKey(KeyBoardBindings.GetBackwardKey()))
            {
                force         = -100f * view;
                keyNotPressed = false;
            }
#endif

            velocity += force * Time.deltaTime;

            if (!velocity.Equals(Vector3.zero))
            {
                this.transform.position += velocity * Time.deltaTime;

                // decelerate
                Vector3 velDir      = velocity.normalized;
                float   decelerator = (5f + velocity.magnitude * 0.5f);
                if (keyNotPressed)
                {
                    decelerator *= 2f;
                }
                else
                {
                    keyNotPressed = true;

                    if (decelerator > 20f)
                    {
                        decelerator = 20f;
                    }
                }
                velocity -= decelerator * velDir * Time.deltaTime;

                double cosOfAngle = (velDir.x * velocity.x + velDir.y * velocity.y + velDir.z * velocity.z);
                if (cosOfAngle < 0)     // -ve, parallel & opp direction
                {
                    velocity = Vector3.zero;
                }
            }

            if (rbody.velocity.magnitude > 0.5f)
            {
                rbody.velocity.Normalize();
                rbody.velocity *= 0.5f;
            }

            // Update the server with position/rotation
            updateInterval += Time.deltaTime;
            if (updateInterval > 0.11f) // 9 times per sec (default unity send rate)
            {
                updateInterval = 0;
                CmdSync(transform.position, transform.rotation, view);
            }
        }
        else
        {
            transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
            transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);
            view = Vector3.Lerp(view, realView, 0.1f);
        }
    }