I’m trying to make a 2D game, where you are a mage and you can shoot on any direction you want. In my current situation, I want that the bullet will go to the crosshair direction, but its not working for me, it goes to anywhere except the cursor. Here my code

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shoot : MonoBehaviour
{
//Will shoot bullet relative to wand end point
[Header("Vars")]
[SerializeField]private Rigidbody2D Bullet;
[SerializeField]private Transform ts;
[SerializeField]private Transform barrell;
[SerializeField]private Transform Player;
[SerializeField]private float thrurst;
//raiz(x2-x1)^2 + (y2-y1)^2
private bool Mouse;
float x1,x2, y1, y2, result, rootX, rootY;
//Vector2 PlayerPos = new Vector2(Player.position.x, Player.position.y);
private void Update()
{
GetMouseInput();
if(Mouse)
{
var newBullet = Instantiate(Bullet, barrell.position, Quaternion.identity) as Rigidbody2D;
float angle = GetAngle();
var Force = findFuckingForces(angle);
newBullet.AddForce(Force * thrurst, ForceMode2D.Impulse);
//newBullet.AddRelativeForce(Vector3.right * thrurst, ForceMode2D.Impulse);
}
}
void GetMouseInput()
{
Mouse = Input.GetMouseButtonDown(0);
}
//It is supposed to find the adjacent side and opposite side, then return it as Vector 2 to pass as instantiate
Vector2 findFuckingForces(float angle)
{
//Gets the hypotenuse the shortest path to a point
x1 = Player.position.x;
x2 = ts.position.x;
y1 = Player.position.y;
y2 = ts.position.y;
Vector2 Pos;
rootX = Mathf.Pow((x2 - x1), 2);
rootY = Mathf.Pow((y2 - y1), 2);
result = Mathf.Sqrt(rootX + rootY);
//acha cateto oposto e adjacente
//cosseno cateto adjacente angulo = cateto adjacente / hipo
//seno cateto oposto angulo = cateto oposto / hipo
float coss = Mathf.Cos(angle);
float seno = Mathf.Sin(angle);
float catetoAdj = coss * result;
float catetoOpst = seno * result;
Pos = new Vector2(catetoOpst, catetoAdj).normalized;
return Pos;
}
//it is Supposed to return an angle between end of wand and where the crosshair is
float GetAngle()
{
x1 = Player.position.x;
x2 = ts.position.x;
y1 = Player.position.y;
y2 = ts.position.y;
float angle = Mathf.Atan2(y2 - y1, x2 - x1) * 180 / Mathf.PI;
Debug.Log(angle);
return angle;
}
}
```

`

I tried using some trigonometry but I don’t know if I did it right.