Advertisement
Myconid

Script "PlayerMovement"

Feb 11th, 2020
527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour
  6. {
  7.  
  8. public float moveSpeed = 5f;
  9. public Rigidbody2D rb;
  10. Vector2 movement;
  11. void Update()
  12. {//check for inputs
  13. movement.x = Input.GetAxisRaw("Horizontal");
  14. movement.y = Input.GetAxisRaw("Vertical");
  15. }
  16.  
  17. void FixedUpdate()
  18. {//for movement
  19. rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
  20. }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement