Exemplo n.º 1
0
        private void MoveForwardBackward(float dt)
        {
            if (characterComponent.Entity.Transform.Position.Y < -10)
            {
                //characterComponent.Orientation
                HadMove = true;
                characterComponent.Teleport(spawnPoint);
            }
            else
            {
                var translationForUpdate = Vector3.Zero;
                var isRunning            = Input.IsKeyDown(Keys.LeftShift) || Input.IsKeyDown(Keys.RightShift);
                var speedToUse           = isRunning ? RunSpeed : WalkSpeed;

                if (ShouldMoveForwards())
                {
                    translationForUpdate.Z = speedToUse.Z;
                    HadMove = true;
                }

                if (ShouldMoveBackwards())
                {
                    translationForUpdate.Z = -speedToUse.Z;
                    HadMove = true;
                }

                translationForUpdate *= dt;

                characterComponent.SetVelocity(translationForUpdate.GetRotationVector(Entity.Transform));

                MovementSpeedChangedEvent.Broadcast(
                    translationForUpdate.Length() <= 0 ? MovementState.Idle :
                    isRunning ? MovementState.Running : MovementState.Walking);
            }
        }