daily pastebin goal
30%
SHARE
TWEET

FirstPersonCamera

Azeranth Mar 19th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class FirstPersonCamera : Camera
  2.     {
  3.         public float speed = 5;
  4.  
  5.         public override void Start()
  6.         {
  7.             MemberScene.InputDispatcher.SubscribeAxisDelegegate(InputAxes.MoveForward, MoveForward);
  8.             MemberScene.InputDispatcher.SubscribeAxisDelegegate(InputAxes.MoveRight, MoveRight);
  9.             MemberScene.InputDispatcher.SubscribeAxisDelegegate(InputAxes.MoveUp, MoveUp);
  10.  
  11.             base.Start();
  12.         }
  13.  
  14.         private void MoveForward(float AxisDelta, float deltaTime)
  15.         {
  16.             var positionDelta = Transform.Forward * AxisDelta * speed * deltaTime;
  17.  
  18.             Transform.Position += positionDelta;
  19.         }
  20.         private void MoveRight(float AxisDelta, float deltaTime)
  21.         {
  22.             Transform.Position += Transform.Right * AxisDelta * speed * deltaTime;
  23.         }
  24.         private void MoveUp(float AxisDelta, float deltaTime)
  25.         {
  26.             Transform.Position += Transform.Up * AxisDelta * speed * deltaTime;
  27.         }
  28.  
  29.         public override void Update(float deltaTime)
  30.         {
  31.             var MouseX = MemberScene.InputDispatcher.Axes[InputAxes.MouseX].GetValue();
  32.             var MouseY = MemberScene.InputDispatcher.Axes[InputAxes.MouseY].GetValue();
  33.  
  34.             Transform.Rotation *= Quaternion.CreateFromYawPitchRoll(MouseX, -MouseY, 0).AsNormal();
  35.             Transform.Rotation.Normalize();
  36.  
  37.             base.Update(deltaTime);
  38.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top