player !pointing and !rotating at mouse position(2DGame)

Hello everyone, here is a basic script for the charakter-Player of my Top-Down-2DGame, and after different experiment I still haven´t been able to let the player rotate in the direction of the mouseCursor., although shooting is actually working. Player is actually rotating around WorldCenter, or not rotating at all!

I am actually using the new InputSystem(ActionType = value; ControlType = Delta; BindingPath = Delta(mouse).
The Camera.Main has a Virtualmachine, following the Player( just as info)

Could you maybe take a look at this. Would me happy to know if I am mistaking something in the script:
_________________________________________________________THANKYOU!
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;

public class Player : MonoBehaviour
{
public float speed = 10f;

[SerializeField] private float maxHealth = 10f;

private float currentHealth;

public Camera cam;

private Rigidbody2D rb;

Vector2 mousePos;
Vector2 lookDir;

private bool canAttack = true;
public GameObject sword;
private SwordDamage swordDamage;

public InputActionReference movementAction;
public InputActionReference lookAtPointer;
public InputActionReference swordAttackAction;
public InputActionAsset inputActions;

public Image healthBar;

public Vector2 Direction { get; private set; } = Vector2.right;

private void Awake()
{
rb = GetComponent();

inputActions.Enable();

currentHealth = maxHealth;

swordDamage = sword.GetComponentInChildren();
}

private void Update()
{
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(lookAtPointer.action.ReadValue());

}

void FixedUpdate()
{
var movementVector = movementAction.action.ReadValue();

if (movementVector.magnitude > 0)//return the lenght of this Vector
Direction = movementVector.normalized;

rb.MovePosition(rb.position + movementVector * speed * Time.deltaTime);
Vector2 lookDir = (mousePos - rb.position).normalized;

float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
rb.rotation = angle;

if (canAttack && swordAttackAction.action.triggered)
{
swordDamage.PerformAttack();
}
}

Please edit your post to use code-tags when posting code.

Thanks.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;


public class PlayerVampire : MonoBehaviour
{
    public float speed = 10f;
    [SerializeField] private float maxHealth = 10f;
    private float currentHealth;

    public Camera cam;
   
    private Rigidbody2D rb;

    Vector2 mousePos;
    Vector2 lookDir;

    private bool canAttack = true;
    public GameObject sword;
    private SwordDamage swordDamage;

    public InputActionReference movementAction;
    public InputActionReference lookAtPointer;
    public InputActionReference swordAttackAction;
    public InputActionAsset inputActions;

    public Image healthBar;

    public Vector2 Direction { get; private set; } = Vector2.right;

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();

        inputActions.Enable();

        currentHealth = maxHealth;

        swordDamage = sword.GetComponentInChildren<SwordDamage>();
    }

    private void Update()
    {
        Debug.Log("yes,Update works!");
        mousePos = Input.mousePosition;
        mousePos = Camera.main.ScreenToWorldPoint(lookAtPointer.action.ReadValue<Vector2>());
        Debug.Log("Oh, my godness a mice!");
    }

    void FixedUpdate()
    {
        var movementVector = movementAction.action.ReadValue<Vector2>();
        //transform.Translate(movementVector * speed * Time.deltaTime);

        //Das ist für den Abfeüern vom Projectile _I_ vom playerPosition aus
        if (movementVector.magnitude > 0)//return the lenght of this Vector
            Direction = movementVector.normalized;

        rb.MovePosition(rb.position + movementVector * speed * Time.deltaTime);
        Vector2 lookDir = (mousePos - rb.position).normalized;
        Debug.DrawRay(rb.position, lookDir, Color.red);
        float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
        rb.rotation = angle;

        if (canAttack && swordAttackAction.action.triggered)
        {
            Debug.Log("Fire2 Pressed");
            swordDamage.PerformAttack();
        }
    }

    public void TakeDamage(float damage)
    {
        currentHealth -= damage;
        healthBar.fillAmount = Math.Clamp(currentHealth / maxHealth, 0, 1);

        if (currentHealth <= 0)
            Debug.Log("YouAreDead");
    }
}

thank to you, now it´s much clearer

Note, you could simply edit your initial post but yes, it’s beter.

        var movementVector = movementAction.action.ReadValue<Vector2>();
        //transform.Translate(movementVector * speed * Time.deltaTime);
        //Das ist für den Abfeüern vom Projectile _I_ vom playerPosition aus
        if (movementVector.magnitude > 0)//return the lenght of this Vector
            Direction = movementVector.normalized;

Is the above code redundant because this sets “Direction” to be normalized, it doesn’t make “movementVector” normalized.

rb.rotation = angle;

There’s MovePosition for a reason but there’s also MoveRotation too. You shouldn’t really set this directly but if you don’t want interpolation then it’ll be fine here but this can cause overlaps with other things.

Most likely is that you’re not checking the input values correctly so they’re wrong. Check that the debug-ray is being draw correctly. If it is then it’ll rotate. The angle calculation is correct although all you’ve said is:

… which I guess could mean anything.

Try the following code in a simple test project and it’ll work:

using UnityEngine;

public class PlayerVampire : MonoBehaviour
{
    public Camera cam;
 
    private Rigidbody2D rb;
    Vector2 mousePos;

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
    }

    private void FixedUpdate()
    {
        var lookDir = (mousePos - rb.position).normalized;
        Debug.DrawRay(rb.position, lookDir, Color.red);
        var angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
        rb.MoveRotation(angle);
    }
}

https://gyazo.com/88dad3cbc24b92955192763a47dbf112