Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using BEPUphysics;
- using BEPUphysics.Character;
- using Microsoft.Xna.Framework.Input;
- using System;
- using System.Diagnostics;
- using BEPUphysics.BroadPhaseEntries.MobileCollidables;
- using ConversionHelper;
- using BEPUutilities;
- namespace BEPUphysicsDemos.AlternateMovement
- {
- public class CharacterControllerInput
- {
- public Camera Camera;
- public CharacterController CharacterController;
- public CharacterCameraControlScheme CameraControlScheme;
- public bool IsActive;
- public Space Space;
- public CharacterControllerInput(Space owningSpace, Camera camera, DemosGame game)
- {
- CharacterController = new CharacterController();
- Camera = camera;
- CameraControlScheme = new CharacterCameraControlScheme(CharacterController, camera, game);
- Space = owningSpace;
- }
- public void Activate()
- {
- if (!IsActive)
- {
- IsActive = true;
- Space.Add(CharacterController);
- CharacterController.Body.Position = Camera.Position - new Vector3(0, CameraControlScheme.StandingCameraOffset, 0);
- }
- }
- public void Deactivate()
- {
- if (IsActive)
- {
- IsActive = false;
- Space.Remove(CharacterController);
- }
- }
- public void Update(float dt, KeyboardState previousKeyboardInput, KeyboardState keyboardInput, GamePadState previousGamePadInput, GamePadState gamePadInput)
- {
- if (IsActive)
- {
- CameraControlScheme.Update(dt);
- Vector2 totalMovement = Vector2.Zero;
- // Changed the keybinds to sanity!
- if (keyboardInput.IsKeyDown(Keys.W))
- {
- totalMovement += new Vector2(0, 1);
- }
- if (keyboardInput.IsKeyDown(Keys.S))
- {
- totalMovement += new Vector2(0, -1);
- }
- if (keyboardInput.IsKeyDown(Keys.A))
- {
- totalMovement += new Vector2(-1, 0);
- }
- if (keyboardInput.IsKeyDown(Keys.D))
- {
- totalMovement += new Vector2(1, 0);
- }
- if (totalMovement == Vector2.Zero)
- {
- CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
- }
- else
- {
- CharacterController.HorizontalMotionConstraint.MovementDirection = Vector2.Normalize(totalMovement);
- }
- if (previousKeyboardInput.IsKeyUp(Keys.Space) && keyboardInput.IsKeyDown(Keys.Space))
- {
- CharacterController.Jump();
- }
- CharacterController.ViewDirection = Camera.WorldMatrix.Forward;
- // --------- This (all the below) is the key addition! --------
- if (flying)
- {
- CharacterController.Body.Position += Camera.WorldMatrix.Forward * totalMovement.Y + Camera.WorldMatrix.Right * totalMovement.X;
- }
- if (keyboardInput.IsKeyDown(Keys.X) && !previousKeyboardInput.IsKeyDown(Keys.X))
- {
- flying = !flying;
- if (flying)
- {
- mass = CharacterController.Body.Mass;
- CharacterController.Body.Mass = 0;
- CharacterController.Body.LinearVelocity = Vector3.Zero;
- }
- else
- {
- CharacterController.Body.Mass = mass;
- }
- }
- }
- }
- bool flying = false;
- float mass;
- Quaternion orient;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement