コード例 #1
0
            private void RemoteUpdate(Vector3 targetPosition)
            {
                playerSpeed = inputController.GetFloat(GMKeyCode.PlayerSpeed);
                float distanceToTarget = Vector3.Distance(new Vector3(transform.position.x, targetPosition.y, transform.position.z), targetPosition);

                if (terrainCollisionHandler != null)
                {
                    terrainCollisionHandler.CollisionCheck();
                }

                if (gameEntity.IsDead())
                {
                    velocity.y -= gravity * Time.deltaTime;
                    SetAnimation(AnimationName.Dead);
                    return;
                }



                Quaternion wanted = Quaternion.Euler(0, inputController.GetFloat(GMKeyCode.Heading), 0);

                transform.rotation = Quaternion.Slerp(transform.rotation, wanted, Time.deltaTime * speed);
                onBoat             = false;



                if (inputController.GetFloat(GMKeyCode.PlayerSpeed) == 1f)
                {
                    speed = runSpeed;
                }
                else
                {
                    speed = walkSpeed;
                }

                if (lastPosition == Vector3.zero)
                {
                    lastPosition = transform.position;
                }
                moveSpeed    = (transform.position - lastPosition).magnitude;
                lastPosition = transform.position;


                UpdateAnimations(distanceToTarget);


                velocity.y -= gravity * Time.deltaTime;

                if (distanceToTarget >= characterController.radius * 2)
                {
                    ServerMove(velocity.y, speed, targetPosition);
                }
            }
コード例 #2
0
            public void ManualUpdate()
            {
                if (gameEntity.IsPlayer())
                {
                    if (Input.GetKeyDown(KeyBinds.Binding("RunWalk")))
                    {
                        if (playerSpeed == 0f)
                        {
                            playerSpeed = 1f;
                        }
                        else
                        {
                            playerSpeed = 0f;
                        }
                    }
                }
                else
                {
                    playerSpeed = inputController.GetFloat(GMKeyCode.PlayerSpeed);
                }

                if (terrainCollisionHandler != null)
                {
                    terrainCollisionHandler.CollisionCheck();
                }

                if (gameEntity.IsDead())
                {
                    velocity.y -= gravity * Time.deltaTime;
                    SetAnimation(AnimationName.Dead);
                    return;
                }

                if (gameEntity.MovementDisabled())
                {
                    velocity.y -= gravity * Time.deltaTime;
                    SetAnimation(AnimationName.Idle);
                    return;
                }

                // If on the ground, allow jumping
                if (grounded)
                {
                    if (inputController.GetBool(GMKeyCode.Jumping))
                    {
                        velocity.y = jumpPower;
                        grounded   = false;
                    }
                }

                if (gameEntity.IsOtherPlayer())
                {
                    Quaternion wanted = Quaternion.Euler(0, inputController.GetFloat(GMKeyCode.Heading), 0);
                    transform.rotation = Quaternion.Slerp(transform.rotation, wanted, Time.deltaTime * speed);
                }


                if (gameEntity.IsPlayer())
                {
                    if (OnBoat())
                    {
                        onBoat = true;
                    }
                    else
                    {
                        onBoat = false;
                    }
                }
                else
                {
                    onBoat = false;
                }


                if (transform.position.y <= swimLevel)
                {
                    swimDirection = 0;
                    float angleY = inputController.GetFloat(GMKeyCode.AngleY);

                    if (angleY >= 40f)
                    {
                        swimDirection = 1;
                    }

                    swimming = true;
                    if (Mathf.Abs(transform.position.y - swimLevel) <= 0.1f)
                    {
                        underWater = false;
                    }
                    else
                    {
                        underWater = true;
                        if (angleY <= -30f || Input.GetButton("Jump"))
                        {
                            swimDirection = 2;
                        }
                    }
                    grounded = true;
                }
                else
                {
                    swimming = false;
                }

                float input_modifier = (inputX != 0.0f && inputY != 0.0f) ? 0.7071f : 1.0f;

                inputX = inputController.GetFloat(GMKeyCode.Haxis);
                inputY = inputController.GetFloat(GMKeyCode.Vaxis);

                // If the user is not holding right-mouse button, rotate the player with the X axis instead of strafing
                if (!inputController.GetBool(GMKeyCode.MouseRight) && inputX != 0)
                {
                    transform.Rotate(new Vector3(0, inputX * (turnSpeed / 2.0f), 0));
                    inputX = 0;
                }

                // Movement direction and speed
                if (swimming)
                {
                    speed = swimSpeed;
                }
                else
                {
                    if (inputY < 0)
                    {
                        speed = backSpeed;
                    }
                    else
                    {
                        if (inputController.GetFloat(GMKeyCode.PlayerSpeed) == 1f)
                        {
                            speed = runSpeed;
                        }
                        else
                        {
                            speed = walkSpeed;
                        }
                    }
                }

                // If on the ground, test to see if still on the ground and apply movement direction
                if (grounded)
                {
                    if (swimming)
                    {
                        velocity = new Vector3(inputX * input_modifier, -antiBump, inputY * input_modifier);
                        velocity = transform.TransformDirection(velocity) * speed;
                        //_velocity = new Vector3 (_velocity.x, y, _velocity.z);
                    }
                    else
                    {
                        velocity = new Vector3(inputX * input_modifier, -antiBump, inputY * input_modifier);
                        velocity = transform.TransformDirection(velocity) * speed;
                    }

                    if (lastPosition == Vector3.zero)
                    {
                        lastPosition = transform.position;
                    }
                    moveSpeed    = (transform.position - lastPosition).magnitude;
                    lastPosition = transform.position;
                }

                // npc's always grounded
                if (gameEntity.IsNpc())
                {
                    grounded = true;
                }
                else
                {
                    //if (!Physics.Raycast(transform.position, -Vector3.up, 0.2f)) {
                    //    grounded = false;
                    //}
                }

                UpdateAnimations();

                if (swimming)
                {
                    if (swimDirection == 2)
                    {
                        swimVelocity = 2f;
                    }
                    else if (swimDirection == 1)
                    {
                        swimVelocity = -2f;
                    }
                    else
                    {
                        swimVelocity = 0f;
                    }

                    velocity.y = swimVelocity;
                }
                else
                {
                    velocity.y -= gravity * Time.deltaTime;
                }

                if (gameEntity.IsPlayer())
                {
                    if (activePlatform == null)
                    {
                        characterController.Move(velocity * Time.deltaTime);
                    }
                    else
                    {
                        if (onBoat)
                        {
                            MoveOnPlatform();
                            if (!controllingBoat)
                            {
                                characterController.Move(velocity * Time.deltaTime);
                            }
                            PlatformPostCalc();
                        }
                    }
                }
                else
                {
                    ServerMove(velocity.y, speed);
                }
            }