Advertisement
jairogv98

PLAYERMOVEMENT

Dec 14th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public float moveSpeed = 5f;
  2.  
  3. Rigidbody2D rb;
  4. public Animator animator;
  5.  
  6. Vector2 movement;
  7. private void Start()
  8. {
  9.  
  10. rb = GetComponent<Rigidbody2D>();
  11. }
  12. void Update()
  13. {
  14.  
  15. animator.SetFloat("Horizontal", movement.x);
  16. animator.SetFloat("Vertical", movement.y);
  17. animator.SetFloat("Speed", movement.sqrMagnitude);
  18.  
  19.  
  20.  
  21. }
  22.  
  23. private void FixedUpdate()
  24. {
  25.  
  26.  
  27. rb.velocity = movement;
  28. }
  29. public void MoverHaciaDelante()
  30. {
  31. movement.y = 1 * moveSpeed;
  32.  
  33.  
  34. }
  35. public void MoverHaciaAtras()
  36. {
  37. movement.y = -1 * moveSpeed;
  38.  
  39. }
  40. public void MoverHaciaDerecha()
  41. {
  42.  
  43.  
  44. movement.x = 1 * moveSpeed;
  45.  
  46. }
  47. public void MoverHaciaIzquierda()
  48. {
  49. movement.x = -1*moveSpeed;
  50. }
  51. public void Parar()
  52. {
  53. movement = Vector2.zero;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement