Rotating GameObject to mousePosition

Hey I recently started using Unity and am trying to design a flash-like arrow shooter game. I want to make my bow snap to the direction of the mouse but it only works on startup even though its in the Update() function. Any ideas on how to fix this? I’ve attached the code. (All credits for code go to Cezary _Sharp on youtube) ``

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bow: MonoBehaviour
{
    public Vector2 Direction;

    public float force;

    public GameObject PointPrefab;
    public GameObject[] Points;

    public int numberOfPoints;

    void Start()
    {
        Points = new GameObject[numberOfPoints];

        for (int i = 0; i< numberOfPoints; i++)
        {
            Points[i] = Instantiate(PointPrefab, transform.position, Quaternion.identity);
        }
    }

    void Update()
    {
        Vector2 MousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        Vector2 bowPos = transform.position;

        Direction = MousePos - bowPos;

        faceMouse();

        for (int i = 0; i< numberOfPoints; i++)
        {
            Points[i].transform.position = PointPosition(i * 0.1f);
        }
    }
    void faceMouse()
    {
        transform.right = Direction;
    }
    Vector2 PointPosition(float t)
    {
        Vector2 currentPointPos = (Vector2)transform.position + (Direction.normalized * force * t) + 0.5f * Physics2D.gravity * (t * t);
        return currentPointPos;
    }
}

You may be able to simply drive transform.forward (or transform.up when in 2D) equal to your movement vector.

Otherwise, use Mathf.Atan2() to derive heading from cartesian coordinates:

Sine/Cosine/Atan2 (sin/cos/atan2) and rotational familiarity and conventions

I know it doesn’t make any sense but it’s probably because you’re not giving ScreenToWorldPoint a z value.

Try doing this:

        Vector3 m=Input.mousePosition;
        Vector3 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(m.x,m.y,1.0f));

I’ve tried both your methods, and though I like the Math.Atan2 approach, the problem persists. I tried to attach a video of what happens when I’ve used the Atan2 approach but direct uploads aren’t allowed it seems

I’ve also tried using the Debug.Log to check if the Update() function is continuous in its activity and, it is. So I’m just really puzzled here.

Tried it but sadly, there was no change. Do you think it could be because I may be missing a few Unity library files? Though that is highly unlikely

Update: I was able to solve the problem by creating a new GameObject and just copy pasting the code, it works now. For some reason, the old GameObject’s rotation was broken, I have no idea why.