Пример #1
0
        private void DestroyRaycast(float length)
        {
            var     m          = Mouse.GetState();
            Vector3 startPoint = Position;
            Vector3 endPoint   = Position + (Direction * length);

            for (int i = 0; i < length * 4; i++)
            {
                Vector3 current = Vector3.Lerp(startPoint, endPoint, (i / 4f) / (length));

                // Check collision
                if (ChunkManager.CheckCollision(current) && m.LeftButton == ButtonState.Pressed && pressed == false)
                {
                    Renderer.AddDebugLine(new DebugLine(startPoint, current, Color.Red));

                    ChunkManager.RemoveBlock(current);

                    pressed = true;
                    return;
                }
                else if (m.LeftButton == ButtonState.Released && pressed == true)
                {
                    pressed = false;
                }
            }
        }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            // If window is focused
            if (Game1.Instance.IsActive)
            {
                GetInput();
                MouseControl();
            }
            else
            {
                First = true;
            }

            if (InputManager.IsKeyDown(Keys.F1))
            {
                IsFlying = true;
            }
            if (InputManager.IsKeyDown(Keys.F2))
            {
                IsFlying = false;
            }

            KeyboardControl();

            if (!IsFlying)
            {
                GroundRay.Start = Position;
                GroundRay.End   = Position - new Vector3(0, HEIGHT, 0);
                CollisionResult?result = CollisionHelper.IsCollidingWithWorld(GroundRay);
                IsGrounded = result != null;

                if (IsGrounded)
                {
                    Position   = Vector3.Lerp(Position, new Vector3(Position.X, result.Value.VoxelPosition.Y + HEIGHT, Position.Z), 0.2f);
                    Velocity.Y = 0;
                }

                else
                {
                    Velocity -= GRAVITY * Up * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }

            Direction = Vector3.Lerp(Direction, TargetDirection, Smoothing);

            DestroyRaycast(25f);

            Position  += Velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            this.Right = Vector3.Normalize(Vector3.Cross(Up, Direction));
            this.View  = Matrix.CreateLookAt(Position, Position + Direction, Up);
        }