Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. Floor floor = World.player.floor;
  2. if (floor != null)
  3. {
  4. int stepTurn = 0;
  5. if (Game.input.justPressed(GameInput.Action.WALK_TURN_LEFT))
  6. {
  7. stepTurn = -1;
  8. }
  9. if (Game.input.justPressed(GameInput.Action.WALK_TURN_RIGHT))
  10. {
  11. stepTurn = 1;
  12. }
  13.  
  14. float playerCurrentAngle = this.transform.eulerAngles.z;
  15. float targetAngle = floor.transform.eulerAngles.z;
  16. targetAngle += Mathf.Round(playerCurrentAngle / 90f) * 90f;
  17. if (stepTurn != 0)
  18. {
  19. this.m_TargetAngleSet = true;
  20. this.m_TargetAngle = targetAngle - 90f * stepTurn;
  21. }
  22. if (this.m_TargetAngleSet)
  23. {
  24. targetAngle = this.m_TargetAngle;
  25. }
  26.  
  27. float angleDiff = Mathf.DeltaAngle(targetAngle,playerCurrentAngle);
  28. if ( this.m_TargetAngleSet && (Mathf.Abs(angleDiff) <= 0f))
  29. {
  30. this.m_TargetAngleSet = false;
  31. }
  32.  
  33. Vector3 playerAngles = this.transform.eulerAngles;
  34. if (Mathf.Abs(angleDiff) > 0f)
  35. {
  36. if (Mathf.Abs(angleDiff) < 5f)
  37. {
  38. playerCurrentAngle = targetAngle;
  39. }
  40. {
  41. playerAngles.z -= Mathf.Lerp(0, angleDiff,Time.deltaTime * 8.0f);
  42. }
  43. this.transform.eulerAngles = playerAngles;
  44. }
  45. } else
  46. {
  47. this.m_TargetAngleSet = false;
  48. int stepTurn = 0;
  49. if (Game.input.down(GameInput.Action.WALK_TURN_LEFT))
  50. {
  51. stepTurn = -1;
  52. }
  53. if (Game.input.down(GameInput.Action.WALK_TURN_RIGHT))
  54. {
  55. stepTurn = 1;
  56. }
  57. if (stepTurn != 0)
  58. {
  59. Vector3 playerAngles = this.transform.eulerAngles;
  60. playerAngles.z += - stepTurn * Time.deltaTime * 90.0f;
  61. this.transform.eulerAngles = playerAngles;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement