bono_u2

Untitled

Oct 20th, 2020
700
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class PlayerControls : MonoBehaviour
  2. {
  3.    
  4.     public Joystick joystick;
  5.     public float speed;
  6.     public float rotZ;
  7.     public float offset;
  8.  
  9.     private Vector2 moveInput;
  10.     private Vector2 moveVelocity;
  11.     private Rigidbody2D rb;
  12.     private PlayerControls Player;
  13.     [SerializeField] private FieldOfView fieldOfView;
  14.  
  15.  
  16.     void Start()
  17.     {
  18.        Player = GetComponent<PlayerControls>();  
  19.         rb = GetComponent<Rigidbody2D>();
  20.        
  21.     }
  22.     void Update()
  23.     {
  24.        
  25.        moveInput = new Vector2(joystick.Horizontal, joystick.Vertical);
  26.        moveVelocity = moveInput.normalized * speed;
  27.  
  28.        if (Mathf.Abs(joystick.Horizontal) > 0.3f || Mathf.Abs(joystick.Vertical) > 0.3f)
  29.         {    
  30.             rotZ = Mathf.Atan2(joystick.Vertical, joystick.Horizontal) * Mathf.Rad2Deg;
  31.         }
  32.         transform.rotation = Quaternion.Euler(0f, 0f, rotZ + offset);
  33.  
  34.         fieldOfView.SetAimDirection(moveInput);
  35.         fieldOfView.SetOrigin(transform.position);
  36.  
  37.  
  38.  
  39.     }
  40.     void FixedUpdate()
  41.     {
  42.             rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
  43.        
  44.       }
  45.  
  46. }
RAW Paste Data