akitheone

Untitled

Oct 11th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1.  
  2. public void Move(Character character, float cameraAngle, Vector3 forwardVector, List<int> keys)
  3. {
  4. float x_temp = 0;
  5. float z_temp = 0;
  6. float yRotation_temp = 0;
  7. float angle = 0;
  8. FacingDirection dirFacing = GetDirectionForAngle(angle);
  9. FacingDirection camFacing = GetDirectionForAngle(cameraAngle);
  10.  
  11. _console.AddLog("Cam facing: " + camFacing.ToString());
  12.  
  13.  
  14. if (keys.Contains((int)KeyInput.W) && keys.Contains((int)KeyInput.A))
  15. {
  16. if (character.AsPlayer()._PlayerState != PlayerState.STRAFING_DIAGONALLY)
  17. {
  18. character.AsPlayer()._PlayerState = PlayerState.STRAFING_DIAGONALLY;
  19.  
  20. character.AsPlayer().PerformAnimation(new Animation("strafe", 0));
  21. }
  22. }
  23. else
  24. {
  25. if (character.AsPlayer()._PlayerState == PlayerState.STRAFING_DIAGONALLY)
  26. {
  27. character.AsPlayer()._PlayerState = PlayerState.IDLE;
  28. }
  29. }
  30. if (character.AsPlayer()._PlayerState != PlayerState.MOVING && character.AsPlayer()._PlayerState != PlayerState.STRAFING_DIAGONALLY)
  31. {
  32. character.AsPlayer()._PlayerState = PlayerState.MOVING;
  33. character.AsPlayer().PerformAnimation(new Animation("run", 0));
  34. }
  35. if (keys.Contains((int)KeyInput.W))
  36. {
  37. //x_temp = (0.055f * (float)Math.Round(Math.Sin(angle * (Math.PI / 180)), 4) * forwardVector.Z);
  38. if (camFacing != FacingDirection.NORTH && camFacing != FacingDirection.SOUTH)
  39. {
  40. x_temp += (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.X);
  41. z_temp += (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.Z);
  42. }
  43. else
  44. {
  45. z_temp = (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.Z);
  46. x_temp = (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.X);
  47. }
  48. }
  49. if (keys.Contains((int)KeyInput.A))
  50. {
  51. if (camFacing != FacingDirection.NORTH && camFacing != FacingDirection.SOUTH)
  52. {
  53. z_temp += (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.X);
  54. } else
  55. x_temp -= (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.Z);
  56. }
  57. if (keys.Contains((int)KeyInput.S))
  58. {
  59. x_temp -= (0.055f * (float)Math.Round(Math.Sin(angle * (Math.PI / 180)), 4) * forwardVector.X);
  60. z_temp -= (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.Z);
  61. }
  62. if (keys.Contains((int)KeyInput.D))
  63. {
  64. if (camFacing != FacingDirection.NORTH && camFacing != FacingDirection.SOUTH)
  65. {
  66. z_temp -= (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.X);
  67. }
  68. else
  69. x_temp += (0.055f * (float)Math.Round(Math.Cos(angle * (Math.PI / 180)), 4) * forwardVector.Z);
  70. }
  71. character._Position.angle = cameraAngle;
  72. //temp new pos
  73. x_temp += character._Position.x;
  74. z_temp += character._Position.z;
  75. yRotation_temp += character._Rotation.Y;
  76.  
  77. if (character.IsPlayer())
  78. {
  79. var player = character.AsPlayer();
  80. player._OldPosition = character.AsPlayer()._Position;
  81. player._OldRotation = new Vector3(0, yRotation_temp, 0);
  82. DetectCollision(player, x_temp, z_temp, yRotation_temp);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment