TeHArGiS10

Untitled

Jun 30th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. private var timer = 0.0;
  2. var bobbingSpeed = 0.18;
  3. var bobbingAmount = 0.2;
  4. var midpoint = 2.0;
  5.  
  6. function Update () {
  7. waveslice = 0.0;
  8. horizontal = Input.GetAxis("Horizontal");
  9. vertical = Input.GetAxis("Vertical");
  10. if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
  11. timer = 0.0;
  12. }
  13. else {
  14. waveslice = Mathf.Sin(timer);
  15. timer = timer + bobbingSpeed;
  16. if (timer > Mathf.PI * 2) {
  17. timer = timer - (Mathf.PI * 2);
  18. }
  19. }
  20. if (waveslice != 0) {
  21. translateChange = waveslice * bobbingAmount;
  22. totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
  23. totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
  24. translateChange = totalAxes * translateChange;
  25. transform.localPosition.y = midpoint + translateChange;
  26. }
  27. else {
  28. transform.localPosition.y = midpoint;
  29. }
  30. }
Add Comment
Please, Sign In to add comment