Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. // (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
  2. /*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
  3.  
  4. using UnityEngine;
  5.  
  6. namespace HutongGames.PlayMaker.Actions
  7. {
  8. [ActionCategory(ActionCategory.Physics)]
  9. [Tooltip("Moves the position of a Rigidbody, calcs and smoothing are internal.")]
  10. public class RigidbodyTranslatePositionAuto : FsmStateAction
  11. {
  12. [RequiredField]
  13. [CheckForComponent(typeof(Rigidbody))]
  14. [Tooltip("The GameObject to move.")]
  15. public FsmOwnerDefault gameObject;
  16.  
  17. [Tooltip("The horizontal axis name as defined in the input manager.")]
  18. public FsmString horizontalAxis;
  19.  
  20. [Tooltip("The vertical axis name as defined in the input manager.")]
  21. public FsmString verticalAxis;
  22.  
  23. [Tooltip("The speed of the rigidbody.")]
  24. public FsmFloat speed;
  25.  
  26. [UIHint(UIHint.Variable)]
  27. public FsmVector3 storeVector;
  28.  
  29. private GameObject go;
  30. private Rigidbody rb;
  31. private Vector3 movement;
  32.  
  33. public override void Reset()
  34. {
  35. gameObject = null;
  36. horizontalAxis = "Horizontal";
  37. verticalAxis = "Vertical";
  38. speed = 5.0f;
  39. storeVector = null;
  40. }
  41.  
  42. public override void Awake()
  43. {
  44. Fsm.HandleFixedUpdate = true;
  45. }
  46.  
  47. public override void OnEnter()
  48. {
  49. go = Fsm.GetOwnerDefaultTarget(gameObject);
  50. rb = go.GetComponent <Rigidbody> ();
  51. }
  52.  
  53. public override void OnFixedUpdate()
  54. {
  55. float h = Input.GetAxisRaw (horizontalAxis.Value);
  56. float v = Input.GetAxisRaw (verticalAxis.Value);
  57.  
  58. DoMovement(h, v);
  59. }
  60.  
  61. void DoMovement(float h, float v)
  62. {
  63. movement.Set (h, 0f, v);
  64. movement = movement.normalized * speed.Value * Time.deltaTime;
  65. rb.MovePosition (go.transform.position + movement);
  66.  
  67. storeVector.Value = movement;
  68.  
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement