Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour
- {
- public float moveSpeed = 5f;
- public Rigidbody2D rbGun;
- public Rigidbody2D rb;
- public Camera cam;
- Vector2 movement;
- Vector2 mousePos;
- void Update()
- {
- movement.x = Input.GetAxisRaw("Horizontal");
- movement.y = Input.GetAxisRaw("Vertical");
- mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
- Walk();
- }
- private void Walk()
- {
- rb.MovePosition(rb.position + movement * moveSpeed * Time.deltaTime);
- // Aim();
- }
- public void Aim()
- {
- mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
- Vector2 lookDir = mousePos - rbGun.position;
- float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg;
- rbGun.rotation = angle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement